async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Enforcing charset in Content-Type is evil

Open fitialovks opened this issue 7 years ago • 1 comments

Sometimes AHC is used to interact with crappy servers and full control over headers is required. In AHC 2.1 Content-Type header is modified regardless of my input:

httpClient.preparePost(authenticationUrl)
    .setBody(byte[])
    .setCharset(null)
    .setHeader("Content-Type", "text/xml")
    .execute()

sends content-type: text/xml; charset=UTF-8 which freaks out the server.

I suggest having two distinct approaches:

  1. setContentType with setCharset that generate this header
  2. setHeader("Content-Type", "text/xml") that overrides whatever was generated

This would be more transparent and flexible.

For now, I will have to rebuild my request using constructor.

See 751a818ff60a263dd3965a9236ac9c8a6e061934

fitialovks avatar Sep 14 '18 15:09 fitialovks

This also breaks aws-signature generation whenever the signature is calculated before the headers are finalized/altered.

mellster2012 avatar Mar 04 '19 23:03 mellster2012