Missing response headers
- Dominant language
- Rust
- Stars
- 396
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
Dear all,
I just discovered an issue while using `ehttp` for some AJAX calls.
Apparently, I can't get all the headers from the HTTP response.
As shown below, iterating over them returns only the two standard ones (content-length and content-type).
Maybe I am missing something, but before diving into the `ehttp` implementation, does anyone have a hint? 🤓
It is added to the UI (an `eframe` based project, ofc) as a dependency like this:
`ehttp = { version = "=0.5.0", features = [ "json" ] }`
And this is the code for this case:
```rust
fn handle_login(user: String, pass: String, sender: Sender, ectx: egui::Context) {
let body = LoginRequest::new(user, pass);
let mut req = ehttp::Request::post("http://localhost:9010/api/login", body.as_json().as_bytes().to_vec());
req.headers.insert("Content-Type", "application/json".to_string());
ehttp::fetch(req, move |rsp| {
match rsp {
Ok(rsp) => {
if rsp.status == 200 {
log::info!("[handle_login] Login successful!");
log::info!("[handle_login] Got response: {:?}", rsp);
log::info!("[handle_login] Got user session: {:?}", rsp.headers.get(APP_HEADER_SESSION));
for (header, value) in rsp.headers {
log::info!("header {}: {}", header, value);
}
let account = serde_json::from_slice::(rsp.bytes.as_slice()).unwrap();
ectx.request_repaint(); // wake up UI thread
if let Err(e) = sender.send(UiMessage::Login(Ok(Some(account)))) {
log::info!("[handle_login] Failed to send Login message. Error: {e}");
}
} else {
log::info!("[handle_login] Login failed! HTTP status code: {}", rsp.status);
let aerr = match rsp.status {
401 => AppError::LoginWrongCredentials,
_ => AppError::from(format!("{}", rsp.status)),
};
if let Err(e) = sender.send(UiMessage::Login(Err(aerr))) {
log::info!("[handle_login] Failed to send Login message. Error: {e}");
}
}
}
Err(e) => log::info!("[handle_login] Login failed! Error: {}", e),
}
});
}
```
Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.