Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert web::types::Payload to AsyncRead #338

Closed
nanakura opened this issue Apr 4, 2024 · 1 comment
Closed

How to convert web::types::Payload to AsyncRead #338

nanakura opened this issue Apr 4, 2024 · 1 comment

Comments

@nanakura
Copy link

nanakura commented Apr 4, 2024

I made some attempts

use futures::TryStreamExt;
use ntex::web;

#[web::get("/")]
async fn hello(body: web::types::Payload) -> impl web::Responder {
    let reader = body.into_async_read();
    web::HttpResponse::Ok().finish()
}

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

I get the following error

error[E0271]: type mismatch resolving `<Payload as Stream>::Item == Result<Bytes, Error>`
    --> src\main.rs:6:23
     |
6    |     let reader = body.into_async_read();
     |                       ^^^^^^^^^^^^^^^ expected `Result<Bytes, Error>`, found `Result<Bytes, PayloadError>`
     |
     = note: expected enum `Result<_, std::io::Error>`
                found enum `Result<_, ntex::http::error::PayloadError>`
     = note: required for `ntex::web::types::Payload` to implement `TryStream`
note: required by a bound in `into_async_read`
@nanakura
Copy link
Author

nanakura commented Apr 4, 2024

I tried implementing it manually

@nanakura nanakura closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant