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
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...)