@Test public void testResponseToA1_0RequestShouldUse1_1() throws Exception { request = new BasicClassicHttpRequest("GET", "/foo"); request.setVersion(new ProtocolVersion("HTTP", 1, 0)); EasyMock.expect( mockExecChain.proceed( EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertEquals(HttpVersion.HTTP_1_1, result.getVersion()); }
/** * 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); }
/** * 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); }
@Test public void testHigherMajorProtocolVersionsOnRequestSwitchToTunnelBehavior() throws Exception { // tunnel behavior: I don't muck with request or response in // any way request = new BasicClassicHttpRequest("GET", "/foo"); request.setVersion(new ProtocolVersion("HTTP", 2, 13)); EasyMock.expect( mockExecChain.proceed( eqRequest(request), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertSame(originResponse, result); }
@Test public void downgrades1_2RequestTo1_1() throws Exception { final HttpRequest req = new BasicHttpRequest("GET", "/"); req.setVersion(new ProtocolVersion("HTTP", 1, 2)); final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion()); }
@Test public void testRequestsWithLowerProtocolVersionsGetUpgradedTo1_1() throws Exception { request = new BasicClassicHttpRequest("GET", "/foo"); request.setVersion(new ProtocolVersion("HTTP", 1, 0)); final ClassicHttpRequest upgraded = new BasicClassicHttpRequest("GET", "/foo"); upgraded.setVersion(HttpVersion.HTTP_1_1); EasyMock.expect( mockExecChain.proceed( eqRequest(upgraded), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertTrue(HttpTestUtils.semanticallyTransparent(originResponse, result)); }
@Test public void testLowerOriginResponsesUpgradedToOurVersion1_1() throws Exception { originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); originResponse.setVersion(new ProtocolVersion("HTTP", 1, 2)); originResponse.setHeader("Date", DateUtils.formatDate(new Date())); originResponse.setHeader("Server", "MockOrigin/1.0"); originResponse.setEntity(body); // not testing this internal behavior in this test, just want // to check the protocol version that comes out the other end EasyMock.expect( mockExecChain.proceed( EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertEquals(HttpVersion.HTTP_1_1, result.getVersion()); }
@Test public void testHigher1_XProtocolVersionsDowngradeTo1_1() throws Exception { request = new BasicClassicHttpRequest("GET", "/foo"); request.setVersion(new ProtocolVersion("HTTP", 1, 2)); final ClassicHttpRequest downgraded = new BasicClassicHttpRequest("GET", "/foo"); downgraded.setVersion(HttpVersion.HTTP_1_1); EasyMock.expect( mockExecChain.proceed( eqRequest(downgraded), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertTrue(HttpTestUtils.semanticallyTransparent(originResponse, result)); }
@Test public void testTransferCodingsAreNotSentToAnHTTP_1_0Client() throws Exception { originResponse.setHeader("Transfer-Encoding", "identity"); final ClassicHttpRequest originalRequest = new BasicClassicHttpRequest("GET", "/foo"); originalRequest.setVersion(new ProtocolVersion("HTTP", 1, 0)); EasyMock.expect( mockExecChain.proceed( EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(originalRequest); verifyMocks(); Assert.assertNull(result.getFirstHeader("TE")); Assert.assertNull(result.getFirstHeader("Transfer-Encoding")); }
@Test public void test100ContinueResponsesAreNotForwardedTo1_0ClientsWhoDidNotAskForThem() throws Exception { final BasicClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/"); post.setVersion(new ProtocolVersion("HTTP", 1, 0)); post.setEntity(body); post.setHeader("Content-Length", "128"); originResponse = new BasicClassicHttpResponse(100, "Continue"); EasyMock.expect( mockExecChain.proceed( EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); try { // if a 100 response gets up to us from the HttpClient // backend, we can't really handle it at that point execute(post); Assert.fail("should have thrown an exception"); } catch (final ClientProtocolException expected) { } verifyMocks(); }
@Test public void testForwardsUnknownHeadersOnRequestsFromHigherProtocolVersions() throws Exception { request = new BasicClassicHttpRequest("GET", "/foo"); request.setVersion(new ProtocolVersion("HTTP", 1, 2)); request.removeHeaders("Connection"); request.addHeader("X-Unknown-Header", "some-value"); final ClassicHttpRequest downgraded = new BasicClassicHttpRequest("GET", "/foo"); downgraded.setVersion(HttpVersion.HTTP_1_1); downgraded.removeHeaders("Connection"); downgraded.addHeader("X-Unknown-Header", "some-value"); EasyMock.expect( mockExecChain.proceed( eqRequest(downgraded), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); execute(request); verifyMocks(); }
throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); return new ProtocolVersion("TLS", major, minor);
((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)));