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

Can't obtain body if headers don't contain content-length #464

Closed
xoac opened this issue Aug 13, 2018 · 7 comments
Closed

Can't obtain body if headers don't contain content-length #464

xoac opened this issue Aug 13, 2018 · 7 comments

Comments

@xoac
Copy link

xoac commented Aug 13, 2018

Code:

extern crate actix_web;
extern crate tokio;
use actix_web::{actix, client, HttpMessage};
use tokio::prelude::*;

fn main() {
    actix::run(|| {
        client::get("http://192.168.50.71/xml/ix.xml")   // <- Create request builder
            .header("User-Agent", "Actix-web")
            .finish().unwrap()
            .send()                               // <- Send http request
            .map_err(|_| ())
            .and_then(|response| {                // <- server http response 
                println!("Response: {:?}", response);

                response.body()                     // <- get Body future
                    .limit(5024)                // <- change max size of the body to a 1kb
                    .map_err(|_e| ())
                    .and_then(|bytes| {
                        println!("body: {:?}", bytes);
                        Ok(())
                   })
            })
    });
}

After run:

Response: 
ClientResponse HTTP/1.1 200 OK
  headers:
    "connection": "close"
    "content-type": "text/xml"
    "server": "lwIP"
    "cache-control": "no-cache"

body: b""

Body is available if I send request through Firefox or curl:

@fafhrd91 on gitter found out in that case responder use content-length = 0.

@DoumanAsh
Copy link
Contributor

afaik if there is no Content-Length or it is not chunked response, we cannot know exactly what is the body.
I think in this case it is right to assume that with no information of body, we should assume no body.

@fafhrd91
Copy link
Member

We need some config for that. Some servers just broken

@Neopallium
Copy link
Member

@DoumanAsh I can't find it in the HTTP/1.1 RFC specs, but there are some HTTP servers that use Connection: close instead of chunked encoding when they don't know the length of the response body.

Go's HTTP response parser has some test cases for handling response bodies without a Content-Length header or chunked encoding:
https://golang.org/src/net/http/response_test.go

@fafhrd91
Copy link
Member

fafhrd91 commented Sep 1, 2018

Client should support be able to read response even without content-length. That is just a reality

@terrence2
Copy link

I am also hitting this. In my case, the target server is a tiny embedded device that I have no control over.

@xoac
Copy link
Author

xoac commented Sep 2, 2018

@terrence2 I have exactly the same problem. Use Client from hyper. It will work in that case

@terrence2
Copy link

0.7.6 solves the issue for me. Thank you for the fast response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants