Skip to content

Commit 8a394ef

Browse files
committed
uefi: http: improve debuggability
1 parent 0bff232 commit 8a394ef

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

uefi/src/proto/network/http.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl Http {
4343
/// Configure HTTP Protocol. Must be called before sending HTTP requests.
4444
pub fn configure(&mut self, config_data: &HttpConfigData) -> uefi::Result<()> {
4545
let status = unsafe { (self.0.configure)(&mut self.0, config_data) };
46+
debug!("http raw: configure({config_data:?}) -> {status}");
4647
match status {
4748
Status::SUCCESS => Ok(()),
4849
_ => Err(status.into()),
@@ -52,6 +53,12 @@ impl Http {
5253
/// Send HTTP request.
5354
pub fn request(&mut self, token: &mut HttpToken) -> uefi::Result<()> {
5455
let status = unsafe { (self.0.request)(&mut self.0, token) };
56+
debug!(
57+
"http raw: request(headers={}, body_len={}) -> {status}, token.status={}",
58+
unsafe { (*token.message).header_count },
59+
unsafe { (*token.message).body_length },
60+
token.status,
61+
);
5562
match status {
5663
Status::SUCCESS => Ok(()),
5764
_ => Err(status.into()),
@@ -70,6 +77,11 @@ impl Http {
7077
/// Receive HTTP response.
7178
pub fn response(&mut self, token: &mut HttpToken) -> uefi::Result<()> {
7279
let status = unsafe { (self.0.response)(&mut self.0, token) };
80+
debug!(
81+
"http raw: response(body_len={}) -> {status}, token.status={}",
82+
unsafe { (*token.message).body_length },
83+
token.status,
84+
);
7385
match status {
7486
Status::SUCCESS => Ok(()),
7587
_ => Err(status.into()),
@@ -211,12 +223,16 @@ impl HttpHelper {
211223
) -> uefi::Result<()> {
212224
let url16 = uefi::CString16::try_from(url).unwrap();
213225

226+
let scheme = url.split(':').next().unwrap_or("<missing>");
214227
let Some(hostname) = url.split('/').nth(2) else {
215228
return Err(Status::INVALID_PARAMETER.into());
216229
};
217230
let mut c_hostname = String::from(hostname);
218231
c_hostname.push('\0');
219-
debug!("http: host: {hostname}");
232+
debug!(
233+
"http: request setup: method={method:?}, scheme={scheme}, host={hostname}, body_len={}",
234+
body.as_ref().map_or(0, |body| body.len())
235+
);
220236

221237
let mut tx_req = HttpRequestData {
222238
method,
@@ -248,12 +264,18 @@ impl HttpHelper {
248264
p.request(&mut tx_token)?;
249265
debug!("http: request sent ok");
250266

267+
let mut polls = 0;
251268
loop {
252269
if tx_token.status != Status::NOT_READY {
253270
break;
254271
}
272+
polls += 1;
255273
p.poll()?;
256274
}
275+
debug!(
276+
"http: request token completed after {polls} polls with {}",
277+
tx_token.status
278+
);
257279

258280
if tx_token.status != Status::SUCCESS {
259281
return Err(tx_token.status.into());

0 commit comments

Comments
 (0)