Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpRequestWrapper


        request = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/foo", new ProtocolVersion("HTTP", 1, 2)));
        request.removeHeaders("Connection");
        request.addHeader("X-Unknown-Header", "some-value");

        final HttpRequestWrapper downgraded = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
        downgraded.removeHeaders("Connection");
        downgraded.addHeader("X-Unknown-Header", "some-value");

        EasyMock.expect(
                mockBackend.execute(
                        EasyMock.isA(HttpRoute.class),
                        eqRequest(downgraded),
View Full Code Here


        impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

        verifyMocks();

        final HttpRequestWrapper forwarded = reqCap.getValue();
        boolean foundExpect = false;
        for (final Header h : forwarded.getHeaders("Expect")) {
            for (final HeaderElement elt : h.getElements()) {
                if ("100-continue".equalsIgnoreCase(elt.getName())) {
                    foundExpect = true;
                    break;
                }
View Full Code Here

        impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

        verifyMocks();

        final HttpRequestWrapper forwarded = reqCap.getValue();
        boolean foundExpect = false;
        for (final Header h : forwarded.getHeaders("Expect")) {
            for (final HeaderElement elt : h.getElements()) {
                if ("100-continue".equalsIgnoreCase(elt.getName())) {
                    foundExpect = true;
                    break;
                }
View Full Code Here

     */
    private void testHEADResponseWithUpdatedEntityFieldsMakeACacheEntryStale(final String eHeader,
            final String oldVal, final String newVal) throws Exception {

        // put something cacheable in the cache
        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final HttpResponse resp1 = HttpTestUtils.make200Response();
        resp1.addHeader("Cache-Control", "max-age=3600");
        resp1.setHeader(eHeader, oldVal);

        // get a head that penetrates the cache
        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("HEAD", "/", HttpVersion.HTTP_1_1));
        req2.addHeader("Cache-Control", "no-cache");
        final HttpResponse resp2 = HttpTestUtils.make200Response();
        resp2.setEntity(null);
        resp2.setHeader(eHeader, newVal);

        // next request doesn't tolerate stale entry
        final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req3.addHeader("Cache-Control", "max-stale=0");
        final HttpResponse resp3 = HttpTestUtils.make200Response();
        resp3.setHeader(eHeader, newVal);

        EasyMock.expect(
                mockBackend.execute(
View Full Code Here

     */
    @Test
    public void test206ResponseGeneratedFromCacheMustHaveContentRangeOrMultipartByteRangesContentType()
            throws Exception {

        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final HttpResponse resp1 = HttpTestUtils.make200Response();
        resp1.setHeader("ETag", "\"etag\"");
        resp1.setHeader("Cache-Control", "max-age=3600");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.setHeader("Range", "bytes=0-50");

        backendExpectsAnyRequestAndReturn(resp1).times(1, 2);

        replayMocks();
        impl.execute(route, req1, context, null);
View Full Code Here

    @Test
    public void test206ResponseGeneratedFromCacheMustHaveABodyThatMatchesContentLengthHeaderIfPresent()
            throws Exception {

        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final HttpResponse resp1 = HttpTestUtils.make200Response();
        resp1.setHeader("ETag", "\"etag\"");
        resp1.setHeader("Cache-Control", "max-age=3600");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.setHeader("Range", "bytes=0-50");

        backendExpectsAnyRequestAndReturn(resp1).times(1, 2);

        replayMocks();
        impl.execute(route, req1, context, null);
View Full Code Here

        }
    }

    @Test
    public void test206ResponseGeneratedFromCacheMustHaveDateHeader() throws Exception {
        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        final HttpResponse resp1 = HttpTestUtils.make200Response();
        resp1.setHeader("ETag", "\"etag\"");
        resp1.setHeader("Cache-Control", "max-age=3600");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.setHeader("Range", "bytes=0-50");

        backendExpectsAnyRequestAndReturn(resp1).times(1, 2);

        replayMocks();
        impl.execute(route, req1, context, null);
View Full Code Here

        verifyMocks();
    }

    @Test
    public void test206ContainsETagIfA200ResponseWouldHaveIncludedIt() throws Exception {
        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));

        originResponse.addHeader("Cache-Control", "max-age=3600");
        originResponse.addHeader("ETag", "\"etag1\"");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.addHeader("Range", "bytes=0-50");

        backendExpectsAnyRequest().andReturn(originResponse).times(1, 2);

        replayMocks();
View Full Code Here

        }
    }

    @Test
    public void test206ContainsContentLocationIfA200ResponseWouldHaveIncludedIt() throws Exception {
        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));

        originResponse.addHeader("Cache-Control", "max-age=3600");
        originResponse.addHeader("Content-Location", "http://foo.example.com/other/url");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.addHeader("Range", "bytes=0-50");

        backendExpectsAnyRequest().andReturn(originResponse).times(1, 2);

        replayMocks();
View Full Code Here

    }

    @Test
    public void test206ResponseIncludesVariantHeadersIfValueMightDiffer() throws Exception {

        final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req1.addHeader("Accept-Encoding", "gzip");

        final Date now = new Date();
        final Date inOneHour = new Date(now.getTime() + 3600 * 1000L);
        originResponse.addHeader("Cache-Control", "max-age=3600");
        originResponse.addHeader("Expires", DateUtils.formatDate(inOneHour));
        originResponse.addHeader("Vary", "Accept-Encoding");

        final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req2.addHeader("Cache-Control", "no-cache");
        req2.addHeader("Accept-Encoding", "gzip");
        final Date nextSecond = new Date(now.getTime() + 1000L);
        final Date inTwoHoursPlusASec = new Date(now.getTime() + 2 * 3600 * 1000L + 1000L);

        final HttpResponse originResponse2 = HttpTestUtils.make200Response();
        originResponse2.setHeader("Date", DateUtils.formatDate(nextSecond));
        originResponse2.setHeader("Cache-Control", "max-age=7200");
        originResponse2.setHeader("Expires", DateUtils.formatDate(inTwoHoursPlusASec));
        originResponse2.setHeader("Vary", "Accept-Encoding");

        final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
        req3.addHeader("Range", "bytes=0-50");
        req3.addHeader("Accept-Encoding", "gzip");

        backendExpectsAnyRequest().andReturn(originResponse);
        backendExpectsAnyRequestAndReturn(originResponse2).times(1, 2);

        replayMocks();
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpRequestWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.