13
13
package org .asynchttpclient .handler ;
14
14
15
15
import static io .netty .handler .codec .http .HttpHeaderNames .CONTENT_LENGTH ;
16
+ import static io .netty .handler .codec .http .HttpHeaderValues .APPLICATION_OCTET_STREAM ;
16
17
import static org .apache .commons .io .IOUtils .copy ;
17
18
import static org .asynchttpclient .Dsl .*;
18
19
import static org .asynchttpclient .test .TestUtils .findFreePort ;
@@ -51,7 +52,7 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
51
52
52
53
httpResponse .setStatus (200 );
53
54
httpResponse .setContentLength (CONTENT_LENGTH_VALUE );
54
- httpResponse .setContentType ("application/octet-stream" );
55
+ httpResponse .setContentType (APPLICATION_OCTET_STREAM . toString () );
55
56
56
57
httpResponse .flushBuffer ();
57
58
@@ -121,7 +122,7 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce
121
122
Response resp = bdah .getResponse ();
122
123
assertNotNull (resp );
123
124
assertEquals (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 ));
125
126
// we got headers only, it's probably not all yet here (we have BIG file
126
127
// downloading)
127
128
assertTrue (cos .getByteCount () <= CONTENT_LENGTH_VALUE );
@@ -179,7 +180,7 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
179
180
Response resp = is .getAsapResponse ();
180
181
assertNotNull (resp );
181
182
assertEquals (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 ));
183
184
// "consume" the body, but our code needs input stream
184
185
CountingOutputStream cos = new CountingOutputStream ();
185
186
try {
@@ -196,8 +197,8 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
196
197
}
197
198
}
198
199
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 {
201
202
try (AsyncHttpClient client = asyncHttpClient (getAsyncHttpClientConfig ())) {
202
203
BoundRequestBuilder r = client .prepareGet ("http://localhost:" + port1 + "/deferredInputStreamTrickWithFailure" ).addHeader ("X-FAIL-TRANSFER" , Boolean .TRUE .toString ());
203
204
PipedOutputStream pos = new PipedOutputStream ();
@@ -211,7 +212,7 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
211
212
Response resp = is .getAsapResponse ();
212
213
assertNotNull (resp );
213
214
assertEquals (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 ));
215
216
// "consume" the body, but our code needs input stream
216
217
CountingOutputStream cos = new CountingOutputStream ();
217
218
try {
@@ -221,9 +222,8 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
221
222
is .close ();
222
223
cos .close ();
223
224
}
224
- fail ("InputStream consumption should fail with IOException!" );
225
225
} catch (IOException e ) {
226
- // good!
226
+ throw e . getCause ();
227
227
}
228
228
}
229
229
}
0 commit comments