String generateViaHeader(final HttpMessage msg) { if (msg.getVersion() == null) { msg.setVersion(HttpVersion.DEFAULT); } final ProtocolVersion pv = msg.getVersion(); final String existingEntry = viaHeaders.get(msg.getVersion()); if (existingEntry != null) { return existingEntry; } final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.hc.client5", getClass().getClassLoader()); final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; final String value; final int major = pv.getMajor(); final int minor = pv.getMinor(); if (URIScheme.HTTP.same(pv.getProtocol())) { value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", major, minor, release); } else { value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), major, minor, release); } viaHeaders.put(pv, value); return value; }
/** * Gets software information as {@code "<name>/<release> (Java/<java.version>)"}. If release is * {@link #UNAVAILABLE}, it will be omitted. * <p> * For example: * <pre>"Apache-HttpClient/4.3 (Java/1.6.0_35)"</pre> * * @param 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} for the thread context class loader * @since 4.3 */ public static String getSoftwareInfo(final String name, final String pkg, final 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"); String nameAndRelease = name; if (!UNAVAILABLE.equals(release)) { nameAndRelease += "/" + release; } return String.format("%s (Java/%s)", nameAndRelease, javaVersion); }
/** * Gets software information as {@code "<name>/<release> (Java/<java.version>)"}. If release is * {@link #UNAVAILABLE}, it will be omitted. * <p> * For example: * <pre>"Apache-HttpClient/4.3 (Java/1.6.0_35)"</pre> * * @param 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} for the thread context class loader * @since 4.3 */ public static String getSoftwareInfo(final String name, final String pkg, final 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"); String nameAndRelease = name; if (!UNAVAILABLE.equals(release)) { nameAndRelease += "/" + release; } return String.format("%s (Java/%s)", nameAndRelease, javaVersion); }
String generateViaHeader(final HttpMessage msg) { if (msg.getVersion() == null) { msg.setVersion(HttpVersion.DEFAULT); } final ProtocolVersion pv = msg.getVersion(); final String existingEntry = viaHeaders.get(msg.getVersion()); if (existingEntry != null) { return existingEntry; } final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.hc.client5", getClass().getClassLoader()); final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; final String value; final int major = pv.getMajor(); final int minor = pv.getMinor(); if (URIScheme.HTTP.same(pv.getProtocol())) { value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", major, minor, release); } else { value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), major, minor, release); } viaHeaders.put(pv, value); return value; }