You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/12/20 18:05:08 UTC
svn commit: r1424591 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt
httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
Author: olegk
Date: Thu Dec 20 17:05:07 2012
New Revision: 1424591
URL: http://svn.apache.org/viewvc?rev=1424591&view=rev
Log:
HTTPCLIENT-900: Don't enforce URI syntax for messages with an explicit target host
Modified:
httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1424591&r1=1424590&r2=1424591&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Dec 20 17:05:07 2012
@@ -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 <olegk at apache.org>
+
* [HTTPCLIENT-1250] Allow query string to be ignored when determining cacheability for HTTP 1.0
responses.
Contributed by Don Brown <mrdon at twdata.org>
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=1424591&r1=1424590&r2=1424591&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java Thu Dec 20 17:05:07 2012
@@ -45,7 +45,6 @@ import org.apache.http.annotation.Immuta
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.CookieSpec
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 implement
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 implement
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
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java?rev=1424591&r1=1424590&r2=1424591&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java Thu Dec 20 17:05:07 2012
@@ -43,6 +43,7 @@ import org.apache.http.client.methods.Ht
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
}
}
+ @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());
+ }
+
}