From a679b4f4ec5af8ca52ae23b05929932f80ea2298 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Fri, 17 May 2013 15:13:55 +0000 Subject: [PATCH] HTTPCLIENT-1351: Preserve last request URI in the execution context) Contributed by James Leigh git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1483848 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 4 ++-- .../http/client/protocol/HttpClientContext.java | 12 +++++++----- .../org/apache/http/impl/execchain/ProtocolExec.java | 5 +---- .../integration/TestClientRequestExecution.java | 3 +++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 937653540..b63ddfc49 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,8 +1,8 @@ Changes since release 4.3 BETA1 ------------------- -* [HTTPCLIENT-1351] Preserve last request URI fragment in the execution context. - Contributed by Oleg Kalnichevski +* [HTTPCLIENT-1351] Preserve last request URI in the execution context. + Contributed by James Leigh * [HTTPCLIENT-1344] Userinfo credentials in URI should not default to preemptive BASIC authentication. diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java index cb2a967de..00af67f3d 100644 --- a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java +++ b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java @@ -27,6 +27,8 @@ package org.apache.http.client.protocol; +import java.net.URI; + import org.apache.http.annotation.NotThreadSafe; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthState; @@ -55,10 +57,10 @@ import org.apache.http.protocol.HttpCoreContext; public class HttpClientContext extends HttpCoreContext { /** - * Attribute name of a {@link String} object that represents - * request URI fragment of the actual request. + * Attribute name of a {@link URI} object that represents + * request URI location (relative or absolute) of the last request target. */ - public static final String URI_FRAGMENT = "http.uri-fragment"; + public static final String HTTP_LOCATION = "http.location"; /** * Attribute name of a {@link org.apache.http.conn.routing.RouteInfo} @@ -158,8 +160,8 @@ public class HttpClientContext extends HttpCoreContext { super(); } - public String getUriFragemnt() { - return getAttribute(URI_FRAGMENT, String.class); + public URI getHttpLocation() { + return getAttribute(HTTP_LOCATION, URI.class); } public RouteInfo getHttpRoute() { diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java index 1a113c4ab..a4d940ad9 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java @@ -79,10 +79,7 @@ public class ProtocolExec implements ClientExecChain { try { URI uri = request.getURI(); if (uri != null) { - final String fragment = uri.getFragment(); - if (fragment != null) { - context.setAttribute(HttpClientContext.URI_FRAGMENT, fragment); - } + context.setAttribute(HttpClientContext.HTTP_LOCATION, uri); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { 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 e1300774e..f56572465 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 @@ -258,6 +258,9 @@ public class TestClientRequestExecution extends IntegrationTestBase { final HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST); Assert.assertEquals("/stuff", request.getRequestLine().getUri()); + + final URI location = (URI) context.getAttribute(HttpClientContext.HTTP_LOCATION); + Assert.assertEquals(uri, location); } }