HTTPCLIENT-900: Don't enforce URI syntax for messages with an explicit target host

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1424591 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-12-20 17:05:07 +00:00
parent 38e6a997fc
commit e99b061a95
3 changed files with 29 additions and 12 deletions

View File

@ -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>

View File

@ -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

View File

@ -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());
}
}