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.