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; }
return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
result = fromMap(pckg, vip, cl);
public static HttpProcessorBuilder customClient(final String agentInfo) { return HttpProcessorBuilder.create() .addAll( new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl(), new RequestUserAgent(!TextUtils.isBlank(agentInfo) ? agentInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new RequestExpectContinue()); }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * {@code null} for the thread context classloader * * @return the version information for all packages found, * never {@code null} */ public static VersionInfo[] loadVersionInfo(final String[] pckgs, final ClassLoader clsldr) { Args.notNull(pckgs, "Package identifier array"); final List<VersionInfo> vil = new ArrayList<>(pckgs.length); for (final String pckg : pckgs) { final VersionInfo vi = loadVersionInfo(pckg, clsldr); if (vi != null) { vil.add(vi); } } return vil.toArray(new VersionInfo[vil.size()]); }
MinimalHttpClient(final HttpClientConnectionManager connManager) { super(); this.connManager = Args.notNull(connManager, "HTTP connection manager"); this.reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE; this.schemePortResolver = DefaultSchemePortResolver.INSTANCE; this.requestExecutor = new HttpRequestExecutor(this.reuseStrategy); this.httpProcessor = new DefaultHttpProcessor( new RequestContent(), new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent(VersionInfo.getSoftwareInfo( "Apache-HttpClient", "org.apache.hc.client5", getClass()))); }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * {@code null} for the thread context classloader * * @return the version information for all packages found, * never {@code null} */ public static VersionInfo[] loadVersionInfo(final String[] pckgs, final ClassLoader clsldr) { Args.notNull(pckgs, "Package identifier array"); final List<VersionInfo> vil = new ArrayList<>(pckgs.length); for (final String pckg : pckgs) { final VersionInfo vi = loadVersionInfo(pckg, clsldr); if (vi != null) { vil.add(vi); } } return vil.toArray(new VersionInfo[vil.size()]); }
private static HttpProcessor createMinimalProtocolProcessor() { return new DefaultHttpProcessor( new H2RequestContent(), new H2RequestTargetHost(), new H2RequestConnControl(), new RequestUserAgent(VersionInfo.getSoftwareInfo( "Apache-HttpAsyncClient", "org.apache.hc.client5", HttpAsyncClients.class))); }
/** * 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); }
result = fromMap(pckg, vip, cl);
return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", Http2Processors.class)), new H2ResponseContent(), new H2ResponseConnControl()) .addAll( new H2RequestValidateHost()); }
/** * 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); }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for client side HTTP/1.1 processing. * * @param agentInfo the agent info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customClient(final String agentInfo) { return HttpProcessorBuilder.create() .addAll( new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(!TextUtils.isBlank(agentInfo) ? agentInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new RequestExpectContinue()); }
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; }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for client side HTTP/1.1 processing. * * @param agentInfo the agent info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customClient(final String agentInfo) { return HttpProcessorBuilder.create() .addAll( new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(!TextUtils.isBlank(agentInfo) ? agentInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new RequestExpectContinue()); }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for server side HTTP/1.1 processing. * * @param serverInfo the server info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new ResponseContent(), new ResponseConnControl()) .addAll( new RequestValidateHost()); }
/** * Creates {@link HttpProcessorBuilder} initialized with default protocol interceptors * for server side HTTP/1.1 processing. * * @param serverInfo the server info text or {@code null} for default. * @return the processor builder. */ public static HttpProcessorBuilder customServer(final String serverInfo) { return HttpProcessorBuilder.create() .addAll( new ResponseDate(), new ResponseServer(!TextUtils.isBlank(serverInfo) ? serverInfo : VersionInfo.getSoftwareInfo(SOFTWARE, "org.apache.hc.core5", HttpProcessors.class)), new ResponseContent(), new ResponseConnControl()) .addAll( new RequestValidateHost()); }
userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpClient", "org.apache.hc.client5", getClass());
userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpAsyncClient", "org.apache.hc.client5", getClass());