HTTPCLIENT-1351: Preserve last request URI in the execution context)

Contributed by James Leigh <james at 3roundstones.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1483848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-05-17 15:13:55 +00:00
parent 45456cf1f0
commit a679b4f4ec
4 changed files with 13 additions and 11 deletions

View File

@ -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 <olegk at apache.org>
* [HTTPCLIENT-1351] Preserve last request URI in the execution context.
Contributed by James Leigh <james at 3roundstones.com>
* [HTTPCLIENT-1344] Userinfo credentials in URI should not default to preemptive BASIC
authentication.

View File

@ -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() {

View File

@ -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()) {

View File

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