maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1172081 - /maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Date Sat, 17 Sep 2011 22:24:32 GMT
Author: olamy
Date: Sat Sep 17 22:24:32 2011
New Revision: 1172081

URL: http://svn.apache.org/viewvc?rev=1172081&view=rev
Log:
restore method setHttpHeaders which is used by core (aether-connector-wagon) to set User-Agent

Modified:
    maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java?rev=1172081&r1=1172080&r2=1172081&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-http-shared4/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
Sat Sep 17 22:24:32 2011
@@ -48,6 +48,7 @@ import org.apache.http.impl.cookie.DateP
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.maven.wagon.InputData;
 import org.apache.maven.wagon.OutputData;
@@ -78,6 +79,8 @@ import java.security.cert.X509Certificat
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
 import java.util.TimeZone;
 import java.util.zip.GZIPInputStream;
 
@@ -359,6 +362,12 @@ public abstract class AbstractHttpClient
     }
 
     /**
+     * @plexus.configuration
+     * @deprecated Use httpConfiguration instead.
+     */
+    private Properties httpHeaders;
+
+    /**
      * @since 1.0-beta-6
      */
     private HttpConfiguration httpConfiguration;
@@ -634,6 +643,7 @@ public abstract class AbstractHttpClient
 
         setParameters( httpMethod );
         setHeaders( httpMethod );
+        client.getParams().setParameter( CoreProtocolPNames.USER_AGENT, getUserAgent( httpMethod
) );
 
         return client.execute( httpMethod );
     }
@@ -671,6 +681,14 @@ public abstract class AbstractHttpClient
             method.addHeader( "Accept-Encoding", "gzip" );
         }
 
+        if ( httpHeaders != null )
+        {
+            for ( Map.Entry<Object, Object> entry : httpHeaders.entrySet() )
+            {
+                method.addHeader( (String) entry.getKey(), (String) entry.getValue() );
+            }
+        }
+
         Header[] headers = config == null ? null : config.asRequestHeaders();
         if ( headers != null )
         {
@@ -681,6 +699,26 @@ public abstract class AbstractHttpClient
         }
     }
 
+    protected String getUserAgent( HttpUriRequest method )
+    {
+        if ( httpHeaders != null )
+        {
+            String value = (String) httpHeaders.get( "User-Agent" );
+            if ( value != null )
+            {
+                return value;
+            }
+        }
+        HttpMethodConfiguration config =
+            httpConfiguration == null ? null : httpConfiguration.getMethodConfiguration(
method );
+
+        if ( config != null )
+        {
+            return (String) config.getHeaders().get( "User-Agent" );
+        }
+        return null;
+    }
+
     /**
      * getUrl
      * Implementors can override this to remove unwanted parts of the url such as role-hints
@@ -864,4 +902,14 @@ public abstract class AbstractHttpClient
     {
         throw new IllegalStateException( "Should not be using the streaming wagon for HTTP
PUT" );
     }
+
+    public Properties getHttpHeaders()
+    {
+        return httpHeaders;
+    }
+
+    public void setHttpHeaders( Properties httpHeaders )
+    {
+        this.httpHeaders = httpHeaders;
+    }
 }



Mime
View raw message