1313package org .asynchttpclient .handler ;
1414
1515import static io .netty .handler .codec .http .HttpHeaderNames .CONTENT_LENGTH ;
16+ import static io .netty .handler .codec .http .HttpHeaderValues .APPLICATION_OCTET_STREAM ;
1617import static org .apache .commons .io .IOUtils .copy ;
1718import static org .asynchttpclient .Dsl .*;
1819import static org .asynchttpclient .test .TestUtils .findFreePort ;
@@ -51,7 +52,7 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
5152
5253httpResponse .setStatus (200 );
5354httpResponse .setContentLength (CONTENT_LENGTH_VALUE );
54- httpResponse .setContentType ("application/octet-stream" );
55+ httpResponse .setContentType (APPLICATION_OCTET_STREAM . toString () );
5556
5657httpResponse .flushBuffer ();
5758
@@ -121,7 +122,7 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce
121122Response resp =bdah .getResponse ();
122123assertNotNull (resp );
123124assertEquals (resp .getStatusCode (),HttpServletResponse .SC_OK );
124- assertEquals (resp .getHeader ("content-length" ),String .valueOf (CONTENT_LENGTH_VALUE ));
125+ assertEquals (resp .getHeader (CONTENT_LENGTH ),String .valueOf (CONTENT_LENGTH_VALUE ));
125126// we got headers only, it's probably not all yet here (we have BIG file
126127// downloading)
127128assertTrue (cos .getByteCount () <=CONTENT_LENGTH_VALUE );
@@ -179,7 +180,7 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
179180Response resp =is .getAsapResponse ();
180181assertNotNull (resp );
181182assertEquals (resp .getStatusCode (),HttpServletResponse .SC_OK );
182- assertEquals (resp .getHeader ("content-length" ),String .valueOf (CONTENT_LENGTH_VALUE ));
183+ assertEquals (resp .getHeader (CONTENT_LENGTH ),String .valueOf (CONTENT_LENGTH_VALUE ));
183184// "consume" the body, but our code needs input stream
184185CountingOutputStream cos =new CountingOutputStream ();
185186try {
@@ -196,8 +197,8 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
196197 }
197198 }
198199
199- @ Test (groups ="standalone" )
200- public void deferredInputStreamTrickWithFailure ()throws IOException , ExecutionException , TimeoutException , InterruptedException {
200+ @ Test (groups ="standalone" , expectedExceptions = RemotelyClosedException . class )
201+ public void deferredInputStreamTrickWithFailure ()throws Throwable {
201202try (AsyncHttpClient client =asyncHttpClient (getAsyncHttpClientConfig ())) {
202203BoundRequestBuilder r =client .prepareGet ("http://localhost:" +port1 +"/deferredInputStreamTrickWithFailure" ).addHeader ("X-FAIL-TRANSFER" ,Boolean .TRUE .toString ());
203204PipedOutputStream pos =new PipedOutputStream ();
@@ -211,7 +212,7 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
211212Response resp =is .getAsapResponse ();
212213assertNotNull (resp );
213214assertEquals (resp .getStatusCode (),HttpServletResponse .SC_OK );
214- assertEquals (resp .getHeader ("content-length" ),String .valueOf (CONTENT_LENGTH_VALUE ));
215+ assertEquals (resp .getHeader (CONTENT_LENGTH ),String .valueOf (CONTENT_LENGTH_VALUE ));
215216// "consume" the body, but our code needs input stream
216217CountingOutputStream cos =new CountingOutputStream ();
217218try {
@@ -221,9 +222,8 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
221222is .close ();
222223cos .close ();
223224 }
224- fail ("InputStream consumption should fail with IOException!" );
225225 }catch (IOException e ) {
226- // good!
226+ throw e . getCause ();
227227 }
228228 }
229229 }