Missing response headers

未关闭
#70 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
rust
领域
networking

调研方向

首先使用 ehttp::fetch 重现该问题,并通过 Response.headers 检查响应标头,使用报告中显示的请求和响应代码。跟踪标头的收集和公开方式,然后验证修复完成后预期的响应标头是否可用。

由索引模型根据 Issue 内容生成。

描述

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!

主要语言
Rust
星标
404
派生
38
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emilk/ehttp 的其他 Issue

查看 emilk/ehttp 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。