/** * Obtains a specific HTTP version. * * @param major the major version * @param minor the minor version * * @return an instance of {@link HttpVersion} with the argument version */ @Override public ProtocolVersion forVersion(final int major, final int minor) { if ((major == getMajor()) && (minor == getMinor())) { return this; } if (major == 1) { if (minor == 0) { return HTTP_1_0; } if (minor == 1) { return HTTP_1_1; } } if ((major == 0) && (minor == 9)) { return HTTP_0_9; } // argument checking is done in the constructor return new HttpVersion(major, minor); }
/** * Obtains a specific HTTP version. * * @param major the major version * @param minor the minor version * * @return an instance of {@link HttpVersion} with the argument version */ @Override public ProtocolVersion forVersion(final int major, final int minor) { if ((major == getMajor()) && (minor == getMinor())) { return this; } if (major == 1) { if (minor == 0) { return HTTP_1_0; } if (minor == 1) { return HTTP_1_1; } } if ((major == 0) && (minor == 9)) { return HTTP_0_9; } // argument checking is done in the constructor return new HttpVersion(major, minor); }
@Test public void testHttpVersionInvalidConstructorInput() throws Exception { try { new HttpVersion(-1, -1); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException e) { // expected } try { new HttpVersion(0, -1); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException e) { // expected } }
buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); return new HttpVersion(major, minor);
buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); return new HttpVersion(major, minor);
@Test public void testHttpVersionEquality() throws Exception { final HttpVersion ver1 = new HttpVersion(1, 1); final HttpVersion ver2 = new HttpVersion(1, 1); Assert.assertTrue((new HttpVersion(0, 9)).equals(HttpVersion.HTTP_0_9)); Assert.assertTrue((new HttpVersion(1, 0)).equals(HttpVersion.HTTP_1_0)); Assert.assertTrue((new HttpVersion(1, 1)).equals(HttpVersion.HTTP_1_1)); Assert.assertFalse((new HttpVersion(1, 1)).equals(HttpVersion.HTTP_1_0));