• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

addHeader Method confusion

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I was just reading book HFJS. I saw two methods

setHeader()
addHeader()

The text says that, the main difference between the two headers is, setHeader over-writes the value if the header exists.
On the contrary, addHeader adds another value to the header which is already present.

So it means that a header can have more then one values? Am i am assuming correct? If that's the case what if we set
the content-type header using addHeader(). In that case how will the browser react, additionally, if more then one value
can be associated, why was it allowed even.

Thanks,
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prithvi,

So it means that a header can have more then one values? Am i am assuming correct? If that's the case what if we set
the content-type header using addHeader().

Yes, some headers can have multiple values like for example Accept-Language: en, us

Not all of them are allowed to have multiple values: it depends on the Headers field definition, have a look at W3C HTML1.1 Header Field Definition

For Content-Type it is not allowed:
Content-Type = "Content-Type" ":" media-type

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic