diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 2f32f00d1..e2799cab7 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes in trunk ------------------- +* [HTTPCLIENT-900] Don't enforce URI syntax for messages with an explicit target host. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1250] Allow query string to be ignored when determining cacheability for HTTP 1.0 responses. Contributed by Don Brown diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java index 33104ca07..1f910f188 100644 --- a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java +++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java @@ -45,7 +45,6 @@ import org.apache.http.annotation.Immutable; import org.apache.http.client.CookieStore; import org.apache.http.client.config.CookieSpecs; import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.config.Lookup; import org.apache.http.conn.routing.RouteInfo; import org.apache.http.cookie.Cookie; @@ -55,6 +54,7 @@ import org.apache.http.cookie.CookieSpecProvider; import org.apache.http.cookie.SetCookie2; import org.apache.http.protocol.HttpContext; import org.apache.http.util.Args; +import org.apache.http.util.TextUtils; /** * Request interceptor that matches cookies available in the current @@ -121,17 +121,12 @@ public class RequestAddCookies implements HttpRequestInterceptor { this.log.debug("CookieSpec selected: " + policy); } - URI requestURI; - if (request instanceof HttpUriRequest) { - requestURI = ((HttpUriRequest) request).getURI(); - } else { - try { - requestURI = new URI(request.getRequestLine().getUri()); - } catch (URISyntaxException ignore) { - requestURI = null; - } + URI requestURI = null; + try { + requestURI = new URI(request.getRequestLine().getUri()); + } catch (URISyntaxException ignore) { } - + String path = requestURI != null ? requestURI.getPath() : null; String hostName = targetHost.getHostName(); int port = targetHost.getPort(); if (port < 0) { @@ -141,7 +136,7 @@ public class RequestAddCookies implements HttpRequestInterceptor { CookieOrigin cookieOrigin = new CookieOrigin( hostName, port >= 0 ? port : 0, - requestURI != null ? requestURI.getPath() : "/", + !TextUtils.isEmpty(path) ? path : "/", route.isSecure()); // Get an instance of the selected cookie policy diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java index aac2d545c..79764ce0d 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java @@ -43,6 +43,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicHttpRequest; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HttpContext; @@ -197,4 +198,22 @@ public class TestClientRequestExecution extends IntegrationTestBase { } } + @Test + public void testNonCompliantURI() throws Exception { + this.localServer.register("*", new SimpleService()); + this.httpclient = HttpClients.createDefault(); + + HttpContext context = new BasicHttpContext(); + BasicHttpRequest request = new BasicHttpRequest("GET", "blah.:.blah.:."); + HttpResponse response = this.httpclient.execute(getServerHttp(), request, context); + EntityUtils.consume(response.getEntity()); + + Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); + + HttpRequest reqWrapper = (HttpRequest) context.getAttribute( + ExecutionContext.HTTP_REQUEST); + + Assert.assertEquals("blah.:.blah.:.", reqWrapper.getRequestLine().getUri()); + } + }