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; }
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; }
@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()); }
/** * 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; }
/** * 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; }
void formatProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version) { buffer.append(version.getProtocol()); buffer.append('/'); buffer.append(Integer.toString(version.getMajor())); buffer.append('.'); buffer.append(Integer.toString(version.getMinor())); }
void formatProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version) { buffer.append(version.getProtocol()); buffer.append('/'); buffer.append(Integer.toString(version.getMajor())); buffer.append('.'); buffer.append(Integer.toString(version.getMinor())); }
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; }
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; }