Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

case of multiple headers

 
Kamal Tripathi
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source: Javabeat Mock exams.

Assuming that the following is a valid request,
GET /Register/index.html HTTP/1.0
Accept-Encoding: gzip, deflate

What would be return type of the method request.getHeader("Accept-Encoding");
a. A string whose value is equal to "gzip, deflate".
b. A string array whose elements are "gzip" and "deflate"
c. A string value whose value is equal to "gzip".
d. A null value.


Answer: Option A is correct. If we would have used request.getHeaders("Accept-Encoding"), then option b is correct.

My question is in this case should I treat Accept-Encoding: gzip, deflate as a header "Accept-Encoding" with value as "gzip, deflate" or is it a header with two values gzip and deflate. I have not seen the request body lot of times so I am confused how much multiple headers look like as part of request. Can someone tell me how would multiple headers appear

P.S. API for request.getHeader("") says "If there are multiple headers with the same name, this method returns the first head in the request." so I chose option C.

Discussion on same topic was done in this thread but it didn't cover my doubts.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's one header with one value. If there are multiple headers then they would occupy multiple lines, each with the header name up front. A tool like the Firefox extension LiveHTTPHeaders can be very useful in observing those headers.
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:That's one header with one value. If there are multiple headers then they would occupy multiple lines, each with the header name up front. A tool like the Firefox extension LiveHTTPHeaders can be very useful in observing those headers.


Is a good extension for firefox.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic