ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Likhite <t...@likhite.net>
Subject Patch: add support for http.agent override
Date Sat, 01 Mar 2014 03:15:16 GMT
We needed this to get Ivy working with a client's extremely paranoid HTTP
proxy setup. It insisted on a specific User-Agent header, so we added
support for -Dhttp.agent (same as Ant).

-- 

Index: src/java/org/apache/ivy/util/url/AbstractURLHandler.java
===================================================================
--- src/java/org/apache/ivy/util/url/AbstractURLHandler.java    (revision
1573075)
+++ src/java/org/apache/ivy/util/url/AbstractURLHandler.java    (working
copy)
@@ -30,6 +30,7 @@
 import java.util.zip.GZIPInputStream;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
+import org.apache.ivy.Ivy;

 public abstract class AbstractURLHandler implements URLHandler {

@@ -62,6 +63,14 @@
         return getURLInfo(url, timeout).getLastModified();
     }

+    protected String getUserAgent() {
+        String userAgent = System.getProperty("http.agent");
+        if (userAgent == null) {
+            userAgent = "Apache Ivy/" + Ivy.getIvyVersion();
+        }
+        return userAgent;
+    }
+
     protected void validatePutStatusCode(URL dest, int statusCode, String
statusMessage)
             throws IOException {
         switch (statusCode) {
Index: src/java/org/apache/ivy/util/url/BasicURLHandler.java
===================================================================
--- src/java/org/apache/ivy/util/url/BasicURLHandler.java    (revision
1573075)
+++ src/java/org/apache/ivy/util/url/BasicURLHandler.java    (working copy)
@@ -64,7 +64,7 @@
         try {
             url = normalizeToURL(url);
             con = url.openConnection();
-            con.setRequestProperty("User-Agent", "Apache Ivy/" +
Ivy.getIvyVersion());
+            con.setRequestProperty("User-Agent", getUserAgent());
             if (con instanceof HttpURLConnection) {
                 HttpURLConnection httpCon = (HttpURLConnection) con;
                 if (getRequestMethod() == URLHandler.REQUEST_METHOD_HEAD) {
@@ -159,7 +159,7 @@
         try {
             url = normalizeToURL(url);
             conn = url.openConnection();
-            conn.setRequestProperty("User-Agent", "Apache Ivy/" +
Ivy.getIvyVersion());
+            conn.setRequestProperty("User-Agent", getUserAgent());
             conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
             if (conn instanceof HttpURLConnection) {
                 HttpURLConnection httpCon = (HttpURLConnection) conn;
@@ -193,7 +193,7 @@
         try {
             src = normalizeToURL(src);
             srcConn = src.openConnection();
-            srcConn.setRequestProperty("User-Agent", "Apache Ivy/" +
Ivy.getIvyVersion());
+            srcConn.setRequestProperty("User-Agent", getUserAgent());
             srcConn.setRequestProperty("Accept-Encoding", "gzip,deflate");
             if (srcConn instanceof HttpURLConnection) {
                 HttpURLConnection httpCon = (HttpURLConnection) srcConn;
@@ -244,7 +244,7 @@
             conn = (HttpURLConnection) dest.openConnection();
             conn.setDoOutput(true);
             conn.setRequestMethod("PUT");
-            conn.setRequestProperty("User-Agent", "Apache Ivy/" +
Ivy.getIvyVersion());
+            conn.setRequestProperty("User-Agent", getUserAgent());
             conn.setRequestProperty("Content-type",
"application/octet-stream");
             conn.setRequestProperty("Content-length",
Long.toString(source.length()));
             conn.setInstanceFollowRedirects(true);
Index: src/java/org/apache/ivy/util/url/HttpClientHandler.java
===================================================================
--- src/java/org/apache/ivy/util/url/HttpClientHandler.java    (revision
1573075)
+++ src/java/org/apache/ivy/util/url/HttpClientHandler.java    (working
copy)
@@ -295,7 +295,7 @@

             // user-agent

httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT,
-                "Apache Ivy/" + Ivy.getIvyVersion());
+                getUserAgent());

             // authentication

httpClient.getParams().setParameter(CredentialsProvider.PROVIDER,


-- 
Tony Likhite

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message