hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r537144 - in /jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http: auth/ impl/client/
Date Fri, 11 May 2007 09:30:14 GMT
Author: olegk
Date: Fri May 11 02:30:13 2007
New Revision: 537144

URL: http://svn.apache.org/viewvc?view=rev&rev=537144
Log:
Implemented request URI rewriting (depending on whether the request is being routed via a
proxy or not)

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScope.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/UsernamePasswordCredentials.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScheme.java
Fri May 11 02:30:13 2007
@@ -62,7 +62,7 @@
  * challenge-response exchanges
  * </p>
  * 
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
  *
  * @since 4.0

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScope.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScope.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScope.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/AuthScope.java Fri
May 11 02:30:13 2007
@@ -37,7 +37,7 @@
  * a port number, a realm name and an authentication scheme name which 
  * {@link Credentials Credentials} apply to.
  * 
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * @author <a href="mailto:adrian@intencha.com">Adrian Sutton</a>
  * 
  * @since 3.0

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/UsernamePasswordCredentials.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/UsernamePasswordCredentials.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/UsernamePasswordCredentials.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/auth/UsernamePasswordCredentials.java
Fri May 11 02:30:13 2007
@@ -38,7 +38,7 @@
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  * @author Sean C. Sullivan
  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * 
  * @version $Revision$ $Date$
  * 

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
Fri May 11 02:30:13 2007
@@ -64,7 +64,7 @@
  * Convenience base class for HTTP client implementations.
  *
  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  * <!-- empty lines to avoid svn diff problems -->
  * @version   $Revision$

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
Fri May 11 02:30:13 2007
@@ -32,6 +32,7 @@
 package org.apache.http.impl.client;
 
 import java.io.IOException;
+import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.commons.logging.Log;
@@ -40,6 +41,7 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
@@ -69,7 +71,7 @@
  * This class replaces the <code>HttpMethodDirector</code> in HttpClient 3.
  *
  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  * <!-- empty lines to avoid svn diff problems -->
  * @version $Revision$
@@ -145,8 +147,8 @@
     }
 
     
-    private RequestWrapper wrapRequest(final RoutedRequest roureq) throws ProtocolException
{
-        HttpRequest request = roureq.getRequest();
+    private RequestWrapper wrapRequest(
+            final HttpRequest request) throws ProtocolException {
         try {
             if (request instanceof HttpEntityEnclosingRequest) {
                 return new EntityEnclosingRequestWrapper(
@@ -162,21 +164,65 @@
     }
     
     
+    private void rewriteRequestURI(
+            final RequestWrapper request,
+            final HttpRoute route) throws ProtocolException {
+        try {
+            
+            URI uri = request.getURI();
+            if (route.getProxyHost() != null && !route.isTunnelled()) {
+                // Make sure the request URI is absolute
+                if (!uri.isAbsolute()) {
+                    HttpHost target = route.getTargetHost();
+                    uri = new URI(
+                            target.getSchemeName(), 
+                            null, 
+                            target.getHostName(), 
+                            target.getPort(), 
+                            uri.getPath(), 
+                            uri.getQuery(), 
+                            uri.getFragment());
+                    request.setURI(uri);
+                }
+            } else {
+                // Make sure the request URI is relative
+                if (uri.isAbsolute()) {
+                    uri = new URI(null, null, null, -1, 
+                            uri.getPath(), 
+                            uri.getQuery(), 
+                            uri.getFragment());
+                    request.setURI(uri);
+                }
+            }
+            
+        } catch (URISyntaxException ex) {
+            throw new ProtocolException("Invalid URI: " + 
+                    request.getRequestLine().getUri(), ex);
+        }
+    }
+    
+    
     // non-javadoc, see interface ClientRequestDirector
     public HttpResponse execute(RoutedRequest roureq, HttpContext context)
         throws HttpException, IOException {
 
-        RequestWrapper request = wrapRequest(roureq);
+        RequestWrapper request = wrapRequest(roureq.getRequest());
         HttpResponse response = null;
         boolean done = false;
 
         try {
             int execCount = 0;
             while (!done) {
+
+                HttpRoute route = roureq.getRoute();
+
+                // Re-write request URI if needed
+                rewriteRequestURI(request, route);
+                
                 if (managedConn == null) {
-                    managedConn = allocateConnection(roureq.getRoute());
+                    managedConn = allocateConnection(route);
                 }
-                establishRoute(roureq.getRoute(), context);
+                establishRoute(route, context);
 
                 context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST,
                         roureq.getRoute().getTargetHost());

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java?view=diff&rev=537144&r1=537143&r2=537144
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java
Fri May 11 02:30:13 2007
@@ -82,7 +82,7 @@
  * This class replaces <code>HttpClient</code> in HttpClient 3.
  *
  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  * <!-- empty lines to avoid svn diff problems -->
  * @version   $Revision$



Mime
View raw message