Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Important ques: setHeader.addHeader

 
amarkirt saroay
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there exists already a header by name and value :
MyHeader: mydata
Now what will be the result of following code on it?



Ans is mydata3,mydata ...Please explain how?
 
Tom Kowalski
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you should write where have you found this question.

Anyway:



when you are using setHeader you are deleting the old contents of the header, and you are puting into it a new value.
when you are using addHeader you are NOT deleting old contents, you just add a new value to this header.
 
amarkirt saroay
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,i took this question from HFJS mock exam.
 
Nicky McGrath
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the real question is:
If you have a Header with multiple values (as occurs after multiple calls to addHeader),
does setHeader replace ALL the existing values.

Good question.
 
Omer Haderi
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the spec is clear about setHeader "the values are cleared and replaced with the new value"

therefore all values will be cleared
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic