sbstp / attohttpc

Rust lightweight HTTP 1.1 client

Home Page:https://docs.rs/attohttpc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timeout silently truncates response body

tdryer opened this issue · comments

Specifying timeout for a request appears to silently truncate the response body if it being received when the the timeout expires.

Example:

http://httpbin.org/drip will return 10 bytes over 2 seconds:

$ time curl "http://httpbin.org/drip"; echo
**********
real    0m2.005s

With a 1 second timeout, curl returns an error:

$ time curl -m 1 "http://httpbin.org/drip"; echo
curl: (28) Operation timed out after 1000 milliseconds with 4 out of 10 bytes received
****
real    0m1.008s

This is an attohttpc program that I expected do the same thing:

use std::time::Duration;

use attohttpc::Result;

fn main() -> Result {
    let resp = attohttpc::get("http://httpbin.org/drip")
        .timeout(Duration::from_secs(1))
        .send()?;
    println!("Status: {:?}", resp.status());
    println!("Body:\n{}", resp.text()?);
    Ok(())
}

But instead of returning an error, the result is successful, and text is truncated:

$ time cargo run --example drip
Status: 200
Body:
*****

real    0m1.178s

Output when running the above MR:

Status: 200
Error: Error(Io(Kind(TimedOut)))

Thanks!