Missing response headers

オープン
#70 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

emilk/ehttp のほかの issue

emilk/ehttp の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。