434578 - Complete listener not called if redirected to an invalid URI.
Fixed by catching the exception and failing properly the redirect.
This commit is contained in:
parent
d92ac8062b
commit
20dbde165e
|
@ -271,7 +271,7 @@ public class HttpRedirector
|
|||
}
|
||||
}
|
||||
|
||||
private Request redirect(final Request request, Response response, Response.CompleteListener listener, URI location, String method)
|
||||
private Request redirect(Request request, Response response, Response.CompleteListener listener, URI location, String method)
|
||||
{
|
||||
HttpRequest httpRequest = (HttpRequest)request;
|
||||
HttpConversation conversation = httpRequest.getConversation();
|
||||
|
@ -281,9 +281,20 @@ public class HttpRedirector
|
|||
if (redirects < client.getMaxRedirects())
|
||||
{
|
||||
++redirects;
|
||||
if (conversation != null)
|
||||
conversation.setAttribute(ATTRIBUTE, redirects);
|
||||
conversation.setAttribute(ATTRIBUTE, redirects);
|
||||
return sendRedirect(httpRequest, response, listener, location, method);
|
||||
}
|
||||
else
|
||||
{
|
||||
fail(request, response, new HttpResponseException("Max redirects exceeded " + redirects, response));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Request sendRedirect(final HttpRequest httpRequest, Response response, Response.CompleteListener listener, URI location, String method)
|
||||
{
|
||||
try
|
||||
{
|
||||
Request redirect = client.copyRequest(httpRequest, location);
|
||||
|
||||
// Use given method
|
||||
|
@ -294,7 +305,7 @@ public class HttpRedirector
|
|||
@Override
|
||||
public void onBegin(Request redirect)
|
||||
{
|
||||
Throwable cause = request.getAbortCause();
|
||||
Throwable cause = httpRequest.getAbortCause();
|
||||
if (cause != null)
|
||||
redirect.abort(cause);
|
||||
}
|
||||
|
@ -303,9 +314,9 @@ public class HttpRedirector
|
|||
redirect.send(listener);
|
||||
return redirect;
|
||||
}
|
||||
else
|
||||
catch (Throwable x)
|
||||
{
|
||||
fail(request, response, new HttpResponseException("Max redirects exceeded " + redirects, response));
|
||||
fail(httpRequest, response, x);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -244,6 +243,38 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest
|
|||
Assert.assertFalse(response.getHeaders().containsKey(HttpHeader.LOCATION.asString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedirectWithWrongScheme() throws Exception
|
||||
{
|
||||
dispose();
|
||||
start(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
baseRequest.setHandled(true);
|
||||
response.setStatus(303);
|
||||
response.setHeader("Location", "ssh://localhost/path");
|
||||
}
|
||||
});
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.path("/path")
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
Assert.assertTrue(result.isFailed());
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRedirectFailed() throws Exception
|
||||
|
|
Loading…
Reference in New Issue