sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Not able to receive HTTP chunked encoded responses #194

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've got a web service that allows clients to download binary files and I'm 
testing the functionality in the following way:

    Response response =
      given().request().
          cookie(createSessionCookie(sessionId)).
      expect().response().statusCode(OK).contentType(expectedContentType).
      when().get(getApiPath("files/" + fileId + "/download"));

And then copying the response back to file (using Apache Commons IOUtils):

    File downloadedFile = new File("test-response-1-file");
    try (FileOutputStream out = new FileOutputStream(downloadedFile)) {
      try (InputStream in = response.asInputStream()) {
        LOG.info("Available: " + in.available());
        IOUtils.copy(in, out);
      }
    }

However, the InputStream is empty when I try to access it (in.available() 
returns 0).

The response is using HTTP chunked encoding, and that's the only reason for 
this problem I could think of.

The response contains headers:

HTTP/1.1 200 OK
Content-Type: audio/mpeg
Transfer-Encoding: chunked

By looking at network packets captured by Wireshark, I can see that immediately 
after receiving the headers, the client (REST-assured) closes the connection 
(using TCP FIN).

I've tested downloading the same file from command line using curl and it works 
perfectly.

According to my tests the regression was introduced in 1.6.2, as I got the 
following results when trying different versions of REST-assured:
- 1.6.1 -> WORKS! chunked encoding works without problems
- 1.6.2 -> FAILS! disconnects after receiving headers
- 1.6.3-SNAPSHOT (from August 26th 2012) -> FAILS! disconnects after receiving 
headers

Original issue reported on code.google.com by mik...@incompleteopus.net on 26 Aug 2012 at 6:53

GoogleCodeExporter commented 9 years ago
Thanks for reporting

Original comment by johan.ha...@gmail.com on 27 Aug 2012 at 12:56

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 3 Sep 2012 at 9:28

GoogleCodeExporter commented 9 years ago
I've now fixed this in trunk. How ever this breaks Rest Assured stress testing 
and I've found no solution that works with both downloading of large (chunked) 
responses and multiple fast & small requests at the same time. So as a 
work-around I've added a ConnectionConfig where you can define if RA should 
drop idle connections after each response or not. Connections must be dropped 
for stress testing but cannot be dropped for chunked downloads (default is 
support for chunked downloads). Please try it out by building from source.

Original comment by johan.ha...@gmail.com on 13 Sep 2012 at 3:30