Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2015-05-28 13:38:28 +0000
committerSimone Bordet2015-05-28 13:38:28 +0000
commit0ad471449ba0d32d7b415633bb1bd92edbeeb822 (patch)
tree05a43b5e4f345c44ea376d387fe5b63fa4614ec9
parentc9be4d10fc3cdddbad860ab9eda5017077732755 (diff)
downloadorg.eclipse.jetty.project-0ad471449ba0d32d7b415633bb1bd92edbeeb822.tar.gz
org.eclipse.jetty.project-0ad471449ba0d32d7b415633bb1bd92edbeeb822.tar.xz
org.eclipse.jetty.project-0ad471449ba0d32d7b415633bb1bd92edbeeb822.zip
468421 - HttpClient#send fails with IllegalArgumentException on non-lowercase schemes.
RFC 7230 specifies that both scheme and host must be case insensitive.
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java3
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java4
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java40
3 files changed, 44 insertions, 3 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
index 1ca2c7598d..3ec0e02cae 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java
@@ -517,7 +517,8 @@ public class HttpClient extends ContainerLifeCycle
if (!HttpScheme.HTTP.is(scheme) && !HttpScheme.HTTPS.is(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);
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
index ad919e5161..7538921792 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java
@@ -161,9 +161,9 @@ public abstract class HttpDestination implements Destination, Closeable, Dumpabl
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);
- if (!getHost().equals(request.getHost()))
+ if (!getHost().equalsIgnoreCase(request.getHost()))
throw new IllegalArgumentException("Invalid request host " + request.getHost() + " for destination " + this);
int port = request.getPort();
if (port >= 0 && getPort() != port)
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java
index df4351fd13..d6eb4e9baa 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.concurrent.TimeUnit;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -431,4 +432,43 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
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());
+ }
}

Back to the top