Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Important ques: setHeader.addHeader

 
amarkirt saroay
Ranch Hand
Posts: 167
  • 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
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic