'actix_web invalid header provided
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.
Solution 1:[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"] }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chandan |