Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3c25a42

Browse files
ssoloffslandelle
authored andcommitted
Fix broken Head302Test (AsyncHttpClient#1421)
* Update Head302Test to show it is actually failingThis test had the following defects which caused it to falsely pass:* Jetty requires a handler to explicitly indicate it has handled therequest by calling Request.setHandled(true). Otherwise the server willreturn 404.* The test did not configure the client to follow redirects.* The test itself wasn't asserting anything useful beyond that therequest did not time out. To ensure the redirect was followed, it needsto assert the expected response status code from the redirected locationis received.* Fix broken Head302TestThe test now verifies that a HEAD redirected via 302 is switched to GETper [1].[1]AsyncHttpClient#989
1 parentaf2e5af commit3c25a42

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

‎client/src/test/java/org/asynchttpclient/Head302Test.java‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
packageorg.asynchttpclient;
1717

1818
importstaticorg.asynchttpclient.Dsl.*;
19+
importstaticorg.testng.Assert.assertEquals;
20+
importstaticorg.testng.Assert.assertTrue;
1921
importstaticorg.testng.Assert.fail;
2022

2123
importjava.io.IOException;
@@ -45,15 +47,15 @@ public class Head302Test extends AbstractBasicTest {
4547
privatestaticclassHead302handlerextendsAbstractHandler {
4648
publicvoidhandle(Strings,org.eclipse.jetty.server.Requestr,HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException {
4749
if ("HEAD".equalsIgnoreCase(request.getMethod())) {
48-
if (request.getPathInfo().endsWith("_moved")) {
49-
response.setStatus(HttpServletResponse.SC_OK);
50-
}else {
51-
response.setStatus(HttpServletResponse.SC_FOUND);// 302
52-
response.setHeader("Location",request.getPathInfo() +"_moved");
53-
}
54-
}else {// this handler is to handle HEAD request
50+
response.setStatus(HttpServletResponse.SC_FOUND);// 302
51+
response.setHeader("Location",request.getPathInfo() +"_moved");
52+
}elseif ("GET".equalsIgnoreCase(request.getMethod())) {
53+
response.setStatus(HttpServletResponse.SC_OK);
54+
}else {
5555
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
5656
}
57+
58+
r.setHandled(true);
5759
}
5860
}
5961

@@ -64,19 +66,23 @@ public AbstractHandler configureHandler() throws Exception {
6466

6567
@Test(groups ="standalone")
6668
publicvoidtestHEAD302()throwsIOException,BrokenBarrierException,InterruptedException,ExecutionException,TimeoutException {
67-
try (AsyncHttpClientclient =asyncHttpClient()) {
69+
AsyncHttpClientConfigclientConfig =newDefaultAsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
70+
try (AsyncHttpClientclient =asyncHttpClient(clientConfig)) {
6871
finalCountDownLatchl =newCountDownLatch(1);
6972
Requestrequest =head("http://localhost:" +port1 +"/Test").build();
7073

71-
client.executeRequest(request,newAsyncCompletionHandlerBase() {
74+
Responseresponse =client.executeRequest(request,newAsyncCompletionHandlerBase() {
7275
@Override
7376
publicResponseonCompleted(Responseresponse)throwsException {
7477
l.countDown();
7578
returnsuper.onCompleted(response);
7679
}
7780
}).get(3,TimeUnit.SECONDS);
7881

79-
if (!l.await(TIMEOUT,TimeUnit.SECONDS)) {
82+
if (l.await(TIMEOUT,TimeUnit.SECONDS)) {
83+
assertEquals(response.getStatusCode(),HttpServletResponse.SC_OK);
84+
assertTrue(response.getUri().getPath().endsWith("_moved"));
85+
}else {
8086
fail("Timeout out");
8187
}
8288
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp