• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

case of multiple headers

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic