hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1411518 - /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
Date Tue, 20 Nov 2012 02:42:16 GMT
Author: ggregory
Date: Tue Nov 20 02:42:15 2012
New Revision: 1411518

URL: http://svn.apache.org/viewvc?rev=1411518&view=rev
Log:
Added the method org.apache.http.util.VersionInfo.setUserAgent(HttpParams, String, String,
Class<?>)
TODO This needs adjusting to account for the deprecated types {@link HttpParams} and {@link
HttpProtocolParams}.

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java?rev=1411518&r1=1411517&r2=1411518&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
Tue Nov 20 02:42:15 2012
@@ -34,6 +34,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+
 
 /**
  * Provides access to version information for HTTP components.
@@ -292,4 +295,29 @@ public class VersionInfo {
         return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
     }
 
+	/**
+	 * Sets the user agent to {@code "<name>/<release> (Java 1.5 minimum; Java/<java.version>)"}.

+	 * <p/>
+	 * For example: 
+	 * <pre>"Apache-HttpClient/4.3 (Java 1.5 minimum; Java/1.6.0_35)"</pre>
+	 * 
+	 * TODO This needs adjusting to account for the deprecated types {@link HttpParams} and
{@link HttpProtocolParams}.
+	 * 
+	 * @param params
+	 *            the HTTP parameters where the user agent will be set
+	 * @name the component name, like "Apache-HttpClient".
+	 * @param pkg
+	 *            the package for which to load version information, for example "org.apache.http".
The package name
+	 *            should NOT end with a dot.
+	 * @param cls
+	 *            the class' class loader to load from, or <code>null</code> for
the thread context class loader
+	 */
+	public static void setUserAgent(HttpParams params, String name, String pkg, Class<?>
cls) {
+		// determine the release version from packaged version info
+		final VersionInfo vi = VersionInfo.loadVersionInfo(pkg, cls.getClassLoader());
+		final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
+		final String javaVersion = System.getProperty("java.version");
+		HttpProtocolParams.setUserAgent(params, name + "/" + release + " (Java 1.5 minimum; Java/"
+ javaVersion + ")");
+	}
+
 } // class VersionInfo



Mime
View raw message