Why does Jersey swallow my “Content-Encoding” header

后端 未结 1 675
忘了有多久
忘了有多久 2020-12-20 23:34

Why does the following example swallow my HTTP-Header for \"Content-Encoding\" in the request. I am writing an application where I need to decode a custom encoding format. H

相关标签:
1条回答
  • 2020-12-20 23:54

    The problem you see is because you are effectively overwriting the Content-Encoding header with the

    .post(Entity.text(QUESTION));
    

    call. The Entity.text(...) method produces entity with the content data Variant fields set to:

    media type = "text/plain";
    content language = null;
    content encoding = null;
    

    These null values of content encoding and language in turn erase any previously set Content-Encoding or Content-Language headers. To fix this, you need to specify the content encoding as part of your entity:

        Response response = target(PATH)
                .request()
                .post(Entity.entity(QUESTION, 
                      new Variant(MediaType.TEXT_PLAIN_TYPE, (String) null, "my-encoding")));
    

    (I agree this behavior is somewhat confusing as it is not obvious. Perhaps we should fix Jersey to not override headers with null variant field values if set...)

    0 讨论(0)
提交回复
热议问题