/** * 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; }
private String generateViaHeader(final HttpMessage msg) { final ProtocolVersion pv = msg.getProtocolVersion(); final String existingEntry = viaHeaders.get(pv); if (existingEntry != null) { return existingEntry; } final VersionInfo vi = VersionInfo.loadVersionInfo("cz.msebera.android.httpclient.client", getClass().getClassLoader()); final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; String value; final int major = pv.getMajor(); final int minor = pv.getMinor(); if ("http".equalsIgnoreCase(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; }
protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpRequest request) { final ProtocolVersion requestProtocol = request.getProtocolVersion(); if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) { return false; } if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) { return true; } return false; }
@Override public CharArrayBuffer appendProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version) { Args.notNull(version, "Protocol version"); // can't use initBuffer, that would clear the argument! CharArrayBuffer result = buffer; final int len = estimateProtocolVersionLen(version); if (result == null) { result = new CharArrayBuffer(len); } else { result.ensureCapacity(len); } result.append(version.getProtocol()); result.append('/'); result.append(Integer.toString(version.getMajor())); result.append('.'); result.append(Integer.toString(version.getMinor())); return result; }