/** * Obtains a specific version of this protocol. * This can be used by derived classes to instantiate themselves instead * of the base class, and to define constants for commonly used versions. * <p> * The default implementation in this class returns {@code this} * if the version matches, and creates a new {@link ProtocolVersion} * otherwise. * </p> * * @param major the major version * @param minor the minor version * * @return a protocol version with the same protocol name * and the argument version */ public ProtocolVersion forVersion(final int major, final int minor) { if ((major == this.major) && (minor == this.minor)) { return this; } // argument checking is done in the constructor return new ProtocolVersion(this.protocol, major, minor); }
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; }
public boolean isSame(final ProtocolVersion protocolVersion) { return version.equals(protocolVersion); }
protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpRequest request) { final ProtocolVersion requestProtocol = request.getVersion(); if (requestProtocol == null) { return false; } if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) { return false; } if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) { return true; } return false; }
/** * Tests if this protocol version is less or equal to the given one. * * @param version the version against which to check this version * * @return {@code true} if this protocol version is * {@link #isComparable comparable} to the argument * and {@link #compareToVersion compares} as less or equal, * {@code false} otherwise */ public final boolean lessEquals(final ProtocolVersion version) { return isComparable(version) && (compareToVersion(version) <= 0); }
@Override public void process( final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException { Args.notNull(context, "HTTP context"); final ProtocolVersion ver = context.getProtocolVersion(); if (ver.getMajor() < 2) { super.process(request, entity, context); } }
public boolean greaterEquals(final ProtocolVersion protocolVersion) { return version.greaterEquals(protocolVersion); }
((new ProtocolVersion("HTTP", 0, 9)).equals(HttpVersion.HTTP_0_9)); Assert.assertTrue ((new ProtocolVersion("HTTP", 1, 0)).equals(HttpVersion.HTTP_1_0)); Assert.assertTrue ((new ProtocolVersion("HTTP", 1, 1)).equals(HttpVersion.HTTP_1_1)); Assert.assertFalse ((new ProtocolVersion("http", 1, 1)).equals(HttpVersion.HTTP_1_1)); (HttpVersion.HTTP_0_9.equals(new ProtocolVersion("HTTP", 0, 9))); Assert.assertTrue (HttpVersion.HTTP_1_0.equals(new ProtocolVersion("HTTP", 1, 0))); Assert.assertTrue (HttpVersion.HTTP_1_1.equals(new ProtocolVersion("HTTP", 1, 1))); Assert.assertFalse (HttpVersion.HTTP_1_1.equals(new ProtocolVersion("http", 1, 1)));
public boolean lessEquals(final ProtocolVersion protocolVersion) { return version.lessEquals(protocolVersion); }
protected boolean requestVersionIsTooLow(final HttpRequest request) { final ProtocolVersion requestProtocol = request.getVersion(); return requestProtocol != null && requestProtocol.compareToVersion(HttpVersion.HTTP_1_1) < 0; }
ProtocolVersion parseProtocolVersion( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { final String protoname = this.protocol.getProtocol(); final int protolength = protoname.length();
public boolean isComparable(final ProtocolVersion protocolVersion) { return version.isComparable(protocolVersion); }
/** * Compares this protocol version with another one. * Only protocol versions with the same protocol name can be compared. * This method does <i>not</i> define a total ordering, as it would be * required for {@link java.lang.Comparable}. * * @param that the protocol version to compare with * * @return a negative integer, zero, or a positive integer * as this version is less than, equal to, or greater than * the argument version. * * @throws IllegalArgumentException * if the argument has a different protocol name than this object, * or if the argument is {@code null} */ public int compareToVersion(final ProtocolVersion that) { Args.notNull(that, "Protocol version"); Args.check(this.protocol.equals(that.protocol), "Versions for different protocols cannot be compared: %s %s", this, that); int delta = getMajor() - that.getMajor(); if (delta == 0) { delta = getMinor() - that.getMinor(); } return delta; }
@Override public void process( final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException { Args.notNull(context, "HTTP context"); final ProtocolVersion ver = context.getProtocolVersion(); if (ver.getMajor() < 2) { super.process(request, entity, context); } }
if (tls.greaterEquals(TLS.V_1_3.version)) { return; } else {
/** * Tests if this protocol version is less or equal to the given one. * * @param version the version against which to check this version * * @return {@code true} if this protocol version is * {@link #isComparable comparable} to the argument * and {@link #compareToVersion compares} as less or equal, * {@code false} otherwise */ public final boolean lessEquals(final ProtocolVersion version) { return isComparable(version) && (compareToVersion(version) <= 0); }
@Override public void process(final HttpRequest request, final EntityDetails entity, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); if (!request.containsHeader(HttpHeaders.EXPECT)) { if (entity != null) { final ProtocolVersion ver = context.getProtocolVersion(); // Do not send the expect header if request body is known to be empty if (entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) { request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE); } } } }
private void transferEncodingIsNotReturnedTo1_0Client( final HttpRequest originalRequest, final HttpResponse response) { final ProtocolVersion version = originalRequest.getVersion() != null ? originalRequest.getVersion() : HttpVersion.DEFAULT; if (version.compareToVersion(HttpVersion.HTTP_1_1) >= 0) { return; } removeResponseTransferEncoding(response); }
ProtocolVersion parseProtocolVersion( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { final String protoname = this.protocol.getProtocol(); final int protolength = protoname.length();
@Test public void testResponseMatchesCacheEntry() throws Exception { final SimpleHttpResponse response = impl.generateResponse(request, entry); Assert.assertTrue(response.containsHeader("Content-Length")); Assert.assertSame("HTTP", response.getVersion().getProtocol()); Assert.assertEquals(1, response.getVersion().getMajor()); Assert.assertEquals(1, response.getVersion().getMinor()); }