Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

actix_web invalid header provided

Tags:

rust

actix-web

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.

like image 287
ferd tomale Avatar asked Aug 15 '26 00:08

ferd tomale


1 Answers

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"] }
like image 104
Chandan Avatar answered Aug 18 '26 06:08

Chandan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!