Missing response headers

Đang mở
#70 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
networking

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện sự cố với ehttp::fetch và kiểm tra các header của response thông qua Response.headers, sử dụng request và mã response được nêu trong báo cáo. Theo dõi cách các header được thu thập và cung cấp, sau đó xác minh rằng các header response mong đợi có sẵn khi bản sửa lỗi hoàn tất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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" ] }

Image

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!

Ngôn ngữ chính
Rust
Star
404
Fork
38
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của emilk/ehttp

Tất cả issue của emilk/ehttp

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.