@Override public void setVersion(final ProtocolVersion version) { response.setVersion(version); }
private static ClassicHttpResponse convert(final SimpleHttpResponse cacheResponse, final ExecChain.Scope scope) { if (cacheResponse == null) { return null; } final ClassicHttpResponse response = new BasicClassicHttpResponse(cacheResponse.getCode(), cacheResponse.getReasonPhrase()); for (final Iterator<Header> it = cacheResponse.headerIterator(); it.hasNext(); ) { response.addHeader(it.next()); } response.setVersion(cacheResponse.getVersion() != null ? cacheResponse.getVersion() : HttpVersion.DEFAULT); final SimpleBody body = cacheResponse.getBody(); if (body != null) { if (body.isText()) { response.setEntity(new StringEntity(body.getBodyText(), body.getContentType())); } else { response.setEntity(new ByteArrayEntity(body.getBodyBytes(), body.getContentType())); } } scope.clientContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); return response; }
@Test public void testViaHeaderOnResponseProperlyRecordsOriginProtocol() throws Exception { originResponse = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content"); originResponse.setVersion(HttpVersion.HTTP_1_0); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); final String via = result.getFirstHeader("Via").getValue(); final String protocol = via.split("\\s+")[0]; final String[] protoParts = protocol.split("/"); Assert.assertTrue(protoParts.length >= 1); Assert.assertTrue(protoParts.length <= 2); if (protoParts.length > 1) { Assert.assertTrue("http".equalsIgnoreCase(protoParts[0])); } Assert.assertEquals("1.0", protoParts[protoParts.length - 1]); }
@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()); }
final String origWarning = "110 fred \"stale\""; originResponse.setCode(HttpStatus.SC_OK); originResponse.setVersion(HttpVersion.HTTP_1_0); originResponse.addHeader("Warning", origWarning); originResponse.setHeader("Date", dateHdr);
@Test public void responseToGetWithQueryFrom1_0OriginAndNoExpiresIsNotCached() throws Exception { final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/bar?baz=quux"); final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); resp2.setVersion(HttpVersion.HTTP_1_0); resp2.setEntity(HttpTestUtils.makeBody(200)); resp2.setHeader("Content-Length","200"); resp2.setHeader("Date", DateUtils.formatDate(now)); backendExpectsAnyRequestAndReturn(resp2); replayMocks(); execute(req2); verifyMocks(); }
@Test public void responseToGetWithQueryFrom1_0OriginVia1_1ProxyAndNoExpiresIsNotCached() throws Exception { final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/bar?baz=quux"); final ClassicHttpResponse resp2 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); resp2.setVersion(HttpVersion.HTTP_1_0); resp2.setEntity(HttpTestUtils.makeBody(200)); resp2.setHeader("Content-Length","200"); resp2.setHeader("Date", DateUtils.formatDate(now)); resp2.setHeader("Via","1.0 someproxy"); backendExpectsAnyRequestAndReturn(resp2); replayMocks(); execute(req2); verifyMocks(); }
@Override protected ClassicHttpResponse createMessage(final CharArrayBuffer buffer) throws IOException, HttpException { final StatusLine statusline = getLineParser().parseStatusLine(buffer); final ClassicHttpResponse response = this.responseFactory.newHttpResponse(statusline.getStatusCode(), statusline.getReasonPhrase()); response.setVersion(statusline.getProtocolVersion()); return response; }
@Override protected ClassicHttpResponse createMessage(final CharArrayBuffer buffer) throws IOException, HttpException { final StatusLine statusline = getLineParser().parseStatusLine(buffer); final ClassicHttpResponse response = this.responseFactory.newHttpResponse(statusline.getStatusCode(), statusline.getReasonPhrase()); response.setVersion(statusline.getProtocolVersion()); return response; }
private static ClassicHttpResponse convert(final SimpleHttpResponse cacheResponse, final ExecChain.Scope scope) { if (cacheResponse == null) { return null; } final ClassicHttpResponse response = new BasicClassicHttpResponse(cacheResponse.getCode(), cacheResponse.getReasonPhrase()); for (final Iterator<Header> it = cacheResponse.headerIterator(); it.hasNext(); ) { response.addHeader(it.next()); } response.setVersion(cacheResponse.getVersion() != null ? cacheResponse.getVersion() : HttpVersion.DEFAULT); final SimpleBody body = cacheResponse.getBody(); if (body != null) { if (body.isText()) { response.setEntity(new StringEntity(body.getBodyText(), body.getContentType())); } else { response.setEntity(new ByteArrayEntity(body.getBodyBytes(), body.getContentType())); } } scope.clientContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); return response; }