You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/01/14 15:57:00 UTC

[jira] [Commented] (HTTPCLIENT-1690) ZipException occurs when content-encoding-header is set for 304-response

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16325642#comment-16325642 ] 

ASF GitHub Bot commented on HTTPCLIENT-1690:
--------------------------------------------

GitHub user catchsudheera opened a pull request:

    https://github.com/apache/httpcomponents-client/pull/91

    HTTPCLIENT-1690: Discarded any Content-Encoding headers coming with 304 status

    Discarded any Content-Encoding headers coming with 304 status code while updating the cache entry. Update performed on cache entry is not updating the content, so we should not update the Content-Encoding header as well ( even if the 304 response has it)

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/catchsudheera/httpcomponents-client remotes/upstream/4.5.x-HTTPCLIENT-1690

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/httpcomponents-client/pull/91.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #91
    
----
commit 494e3bffe5811750b8fcbd89d2af4485c549f86b
Author: Sudheera Palihakkara <ca...@...>
Date:   2018-01-14T15:49:50Z

    HTTPCLIENT-1690: Discarded any Content-Encoding header coming with 304 status code while updating the cache entry. Added a test case to test that scenario

----


> ZipException occurs when content-encoding-header is set for 304-response 
> -------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1690
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1690
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpCache
>    Affects Versions: 4.5
>            Reporter: Johannes Gruber
>              Labels: stuck, volunteers-wanted
>             Fix For: Stuck
>
>
> h4.Test scenario
> - Setup http server
> - Execute Request twice
> - First response
> -- Status: 200
> -- Cache-Control: public
> -- ETag: 123
> -- Body: some text
> - Second response
> -- Status: 304
> -- Content-Encoding: gzip
> - Effect: java.util.zip.ZipException: Not in GZIP format
> - Expected: Cached response
> h4.JUnit-Test
> - Dependencies: junit 4.11, commons-io 2.4, com.github.tomakehurst:wiremock 1.57
> {code}
> import com.github.tomakehurst.wiremock.junit.WireMockRule;
> import org.apache.commons.io.IOUtils;
> import org.apache.http.client.methods.CloseableHttpResponse;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.client.CloseableHttpClient;
> import org.apache.http.impl.client.HttpClientBuilder;
> import org.apache.http.impl.client.cache.CacheConfig;
> import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
> import org.junit.Assert;
> import org.junit.Rule;
> import org.junit.Test;
> import java.io.IOException;
> import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
> import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
> import static com.github.tomakehurst.wiremock.client.WireMock.get;
> import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
> import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
> public class GZipCachingHttpClientBuilderTest  {
>   private static final String TEST_BODY = "Sometext";
>   @Rule
>   public WireMockRule wireMockRule = new WireMockRule(0);
>   @Test
>   public void testGzipError() throws Exception {
>     stubFor(get(urlEqualTo("/my/resource"))
>         .willReturn(aResponse()
>                 .withStatus(200)
>                 .withHeader("Cache-Control", "public")
>                 .withHeader("ETag", "123")
>                 .withBody(TEST_BODY)
>         ));
>     stubFor(get(urlEqualTo("/my/resource"))
>         .withHeader("If-None-Match", equalTo("123"))
>         .willReturn(aResponse()
>                 .withHeader("Content-Encoding", "gzip")
>                 .withStatus(304)
>         ));
>     CacheConfig.Builder cfgBuilder = CacheConfig.custom();
>     CacheConfig cfg = cfgBuilder.setMaxCacheEntries(1024).build();
>     HttpClientBuilder bld = CachingHttpClientBuilder.create().setCacheConfig(cfg);
>     CloseableHttpClient client = bld.build();
>     executeRequest(client);
>     executeRequest(client); // second request causes Exception :-(
>   }
>   private void executeRequest(CloseableHttpClient client) throws IOException {
>     int port = wireMockRule.port();
>     CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:"+port+"/my/resource"));
>     Assert.assertEquals(TEST_BODY, IOUtils.toString(resp.getEntity().getContent()));
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org