-
Notifications
You must be signed in to change notification settings - Fork 37
Open
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:
fn handle_login(user: String, pass: String, sender: Sender<UiMessage>, 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::<UserAccount>(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!
Metadata
Metadata
Assignees
Labels
No labels