• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request headers question ...

 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anybody help me in this

This is one of the questions in the HFSJ final mock,



Which "a" will be set ? The second one or there will be only one header named "a" with the value of "c" ?

Thanks in advance ...
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addHeader adds the header to the existing value
setHeader replaces it.

So header 'a' will have the value of 'c' at the end of these lines.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I got it now

Thanks ...
 
Tanveer Ahmad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addHeader & setHeader work like this... If "a" DOES NOT exist then "a" is set (NOTE here I have used SET... simple...). If "a" DOES exist then addHeader ADDS (menas add the existing value) but the setHeader SETS (means overwrite existing value).
So the answer will be "c", since last statement is setHeader("a", "c");
Had it been like addHeader("a", "c"); then outcome would be "abc".

Hope this helps.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It became even more clear, thanks Tanveer ...

Best of luck ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic