Skip to content

Fix broken Head302Test #1421

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

Merged
merged 2 commits into from
Jun 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions client/src/test/java/org/asynchttpclient/Head302Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.asynchttpclient;

import static org.asynchttpclient.Dsl.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import java.io.IOException;
Expand Down Expand Up @@ -45,15 +47,15 @@ public class Head302Test extends AbstractBasicTest {
private static class Head302handler extends AbstractHandler {
public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if ("HEAD".equalsIgnoreCase(request.getMethod())) {
if (request.getPathInfo().endsWith("_moved")) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.setStatus(HttpServletResponse.SC_FOUND); // 302
response.setHeader("Location", request.getPathInfo() + "_moved");
}
} else { // this handler is to handle HEAD request
response.setStatus(HttpServletResponse.SC_FOUND); // 302
response.setHeader("Location", request.getPathInfo() + "_moved");
} else if ("GET".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

r.setHandled(true);
}
}

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

@Test(groups = "standalone")
public void testHEAD302() throws IOException, BrokenBarrierException, InterruptedException, ExecutionException, TimeoutException {
try (AsyncHttpClient client = asyncHttpClient()) {
AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
try (AsyncHttpClient client = asyncHttpClient(clientConfig)) {
final CountDownLatch l = new CountDownLatch(1);
Request request = head("http://localhost:" + port1 + "/Test").build();

client.executeRequest(request, new AsyncCompletionHandlerBase() {
Response response = client.executeRequest(request, new AsyncCompletionHandlerBase() {
@Override
public Response onCompleted(Response response) throws Exception {
l.countDown();
return super.onCompleted(response);
}
}).get(3, TimeUnit.SECONDS);

if (!l.await(TIMEOUT, TimeUnit.SECONDS)) {
if (l.await(TIMEOUT, TimeUnit.SECONDS)) {
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
assertTrue(response.getUri().getPath().endsWith("_moved"));
} else {
fail("Timeout out");
}
}
Expand Down