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

When it is a POST request, the socket cannot be closed #385

Closed
Merely-chao opened this issue Jul 24, 2024 · 1 comment
Closed

When it is a POST request, the socket cannot be closed #385

Merely-chao opened this issue Jul 24, 2024 · 1 comment

Comments

@Merely-chao
Copy link

service code:

dependencies:

[dependencies]
tokio = { version = "1", features = ["full"] }
env_logger = "0.11"
log = "0.4.21"
ntex = { version = "2.0.3", features = ["tokio"] }
serde = "1.0.204"
#[derive(Deserialize)]
struct Info {
    username: String,
}


async fn submit(info: web::types::Json<Info>) -> Result<String, web::Error> {
    Ok(format!("Welcome {}!", info.username))
}

#[ntex::main]
async fn main()  -> std::io::Result<()> {
    std::env::set_var("RUST_LOG", "trace");
    env_logger::init();
    web::HttpServer::new(|| {
     let json_config = web::types::JsonConfig::default().limit(4096);

     web::App::new().service(
         web::resource("/")
         
             .state(json_config)
             .route(web::post().to(submit)),
     )
 })
 .bind(("127.0.0.1", 8080))?
 .run()
 .await
}

service log:

[2024-07-24T02:51:40Z TRACE ntex_tokio::io] : Write task is instructed to terminate
[2024-07-24T02:51:49Z TRACE ntex::http::service] New http connection, peer address Some(127.0.0.1:63741)
[2024-07-24T02:51:49Z DEBUG ntex_io::ioref] : Start timer Seconds(1)
[2024-07-24T02:51:49Z DEBUG ntex_io::timer] : Timer driver does not run, current: 0
[2024-07-24T02:51:49Z TRACE ntex::http::h1::dispatcher] : Trying to read http message
[2024-07-24T02:51:49Z TRACE ntex_io::tasks] : New 342 bytes available, wakeup dispatcher
[2024-07-24T02:51:49Z TRACE ntex::http::h1::dispatcher] : Trying to read http message
[2024-07-24T02:51:49Z TRACE ntex::http::h1::dispatcher] : Http message is received:
    Request HTTP/1.1 POST:/
      headers:
        "accept": "*/*"
        "content-type": "application/json;charset=UTF-8"
        "cpgrade": "h2c"
        "connection": "Upgrade, HTTP2-Settings"
        "accept-encoding": "gzip, deflate"
        "http2-settings": "AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA"
        "content-length": "45"
        "host": "localhost:8080"
        "user-agent": "python-requests/2.32.3"
     and payload Payload(PayloadDecoder { kind: Cell { value: Length(45) } })
[2024-07-24T02:51:49Z DEBUG ntex_io::ioref] : Stop timer


client: Python

Always waiting for the content to be returned

import requests


url = "http://localhost:8080/"
headers = {
    "Content-Type": "application/json;charset=UTF-8",
    "Connection": "Upgrade, HTTP2-Settings",
    "Cpgrade": "h2c",
    "http2-settings": "AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA"
    }

jsonData= {"username":"af1413d0-18a6-4e89-ba76-f0b9594bc45b"}

response = requests.post(url,json= jsonData,headers=headers)
print(response.text) 
@fafhrd91
Copy link
Member

thanks for reporting!

ntex 2.1.0 fixes the problem

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

2 participants