468421 - HttpClient#send fails with IllegalArgumentException on non-lowercase schemes.
RFC 7230 specifies that both scheme and host must be case insensitive.
This commit is contained in:
parent
c9be4d10fc
commit
0ad471449b
|
@ -517,7 +517,8 @@ public class HttpClient extends ContainerLifeCycle
|
||||||
if (!HttpScheme.HTTP.is(scheme) && !HttpScheme.HTTPS.is(scheme))
|
if (!HttpScheme.HTTP.is(scheme) && !HttpScheme.HTTPS.is(scheme))
|
||||||
throw new IllegalArgumentException("Invalid protocol " + scheme);
|
throw new IllegalArgumentException("Invalid protocol " + scheme);
|
||||||
|
|
||||||
HttpDestination destination = destinationFor(scheme, request.getHost(), request.getPort());
|
String host = request.getHost().toLowerCase(Locale.ENGLISH);
|
||||||
|
HttpDestination destination = destinationFor(scheme, host, request.getPort());
|
||||||
destination.send(request, listeners);
|
destination.send(request, listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,9 +161,9 @@ public abstract class HttpDestination implements Destination, Closeable, Dumpabl
|
||||||
|
|
||||||
protected void send(HttpRequest request, List<Response.ResponseListener> listeners)
|
protected void send(HttpRequest request, List<Response.ResponseListener> listeners)
|
||||||
{
|
{
|
||||||
if (!getScheme().equals(request.getScheme()))
|
if (!getScheme().equalsIgnoreCase(request.getScheme()))
|
||||||
throw new IllegalArgumentException("Invalid request scheme " + request.getScheme() + " for destination " + this);
|
throw new IllegalArgumentException("Invalid request scheme " + request.getScheme() + " for destination " + this);
|
||||||
if (!getHost().equals(request.getHost()))
|
if (!getHost().equalsIgnoreCase(request.getHost()))
|
||||||
throw new IllegalArgumentException("Invalid request host " + request.getHost() + " for destination " + this);
|
throw new IllegalArgumentException("Invalid request host " + request.getHost() + " for destination " + this);
|
||||||
int port = request.getPort();
|
int port = request.getPort();
|
||||||
if (port >= 0 && getPort() != port)
|
if (port >= 0 && getPort() != port)
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -431,4 +432,43 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
|
||||||
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
|
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSchemeIsCaseInsensitive() throws Exception
|
||||||
|
{
|
||||||
|
start(new AbstractHandler()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
|
{
|
||||||
|
baseRequest.setHandled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||||
|
.scheme(scheme.toUpperCase())
|
||||||
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
|
||||||
|
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHostIsCaseInsensitive() throws Exception
|
||||||
|
{
|
||||||
|
start(new AbstractHandler()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
|
{
|
||||||
|
baseRequest.setHandled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ContentResponse response = client.newRequest("LOCALHOST", connector.getLocalPort())
|
||||||
|
.scheme(scheme)
|
||||||
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
|
||||||
|
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue