actix_web invalid header provided
Asked Answered
B

2

7

I am getting this error running an actix-web based server

ERROR actix_http::h1::dispatcher] stream error: Request parse error: Invalid Header provided

The handler code is this:

#[derive(Serialize, Deserialize)]
pub struct Data {
   some_data: String
};
async fn handler_post(
  request: HttpRequest,
  data: web::Json<Data>
) -> impl Responder {
  HttpResponse::OK()
     .json(ApiResponse {
        status: "success"
     })
}

The headers being sent are accept, Content-Type and User-Agent. I don't know how to make it work. By the way, i'm using actix-web 4.

Brink answered 3/4, 2022 at 9:6 Comment(4)
please add the request and Cargo.toml in your question.Maryettamaryjane
I'm having a similar issue, can't figure out the causeDeath
I actually fixed my issue but forgot to post the answer. It wasn't header related at all. I forgot what I changed. Can you post your code? It might jog my memory.Brink
I've seen the same error message in AWS logs....it turned out to be completely different issue. In my case, I was servicing a non-existent static dir. fixing my paths etc resurrected my appCatarina
M
1

I tried the handler with actix version 4 and facing no issue

src/main.rs

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest};
use serde::{Serialize, Deserialize};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello world!")
}

#[derive(Serialize, Deserialize)]
pub struct Data {
   some_data: String
}

#[derive(Serialize, Deserialize)]
pub struct ApiResponse<'a> {
   status: &'a str
}

#[post("/")]
async fn handler_post(
  request: HttpRequest,
  data: web::Json<Data>
) -> impl Responder {
  HttpResponse::Ok()
     .json(ApiResponse {
        status: "success"
     })
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(hello)
            .service(handler_post)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

Cargo.toml

[package]
name = "..."
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
serde = { version = "1.0", features = ["derive"] }
Maryettamaryjane answered 14/5, 2022 at 17:44 Comment(0)
K
0

I am facing the same issue today, seems a raw utf8 issue. when the request contains chinese words. will show this error, after moved the chinese words, works fine. More information from here: https://github.com/seanmonstar/httparse/issues/146

Krisha answered 2/5 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.