restify / clients

HttpClient, StringClient, and JsonClient extracted from restify
MIT License
57 stars 34 forks source link

Not able to set Content-Type with UTF-8 in header #144

Open Nordes opened 6 years ago

Nordes commented 6 years ago

Hi, maybe I am doing it wrong, but I am not able to set the CharSet in the headers.

(Needed to send some japanese body) Usually in postman: Content-Type: application/json; charset=UTF-8

I`ve tried to set the headers :

{ 'Content-Type': 'application/json; charset=UTF-8' }

But it fails. It still send the wrong text.

Nordes commented 6 years ago

I was actually able to set it like the following:

  1. Create the client (with options...)
  2. myClient.headers["content-type"] = 'application/json; charset=UTF-8'

I previously tried using the creation options contentType but it didn't change anything. Was it a wanted behavior?

DonutEspresso commented 6 years ago

Hi @Nordes , you can set headers using the options 'headers':

client.post({ 
  headers: { 
    'content-type': 'foobarbaz' 
  }, 
  path: '/' 
}, function() { ... });

That said, for content-type specifically, we seem to be deleting content-type headers for GET/HEAD/DELETE verbs. While generally this seems reasonable, in reading the RFC it doesn't actually suggest that content-type is required (or disallowed) based on the verbs. This seems like a legitimate bug.