Servlet Development Guide : PART III Programming : Chapter 7 Working With Requests : Inspecting HTTP Headers
Inspecting HTTP Headers
A rwsf::HttpServletRequest contains the headers transmitted with the client’s original HTTP request. The servlet request provides the function getHeader() for retrieving the value associated with a given header. For example, the code sample below retrieves the value of the Referer HTTP header:
 
std::string referer = request.getHeader("Referer");
If the request from the client does not contain a Referer header, getHeader() returns an empty string.
Some request headers may contain more than one value. For those headers, the getHeader() function returns the first value. To retrieve the complete set of values, use the getHeaders() function. The code sample below retrieves the list of values contained in the Accept HTTP header:
 
rwsf::Enumeration<std::string> acceptVals =
request.getHeaders("Accept");
If the request from the client does not contain an Accept header, the enumeration contains no elements. If the Accept header contains only one value, the enumeration contains one element.
To retrieve the names of the headers in the request, use the getHeaderNames() function. The line of code below retrieves a list of the headers that the request contains:
 
rwsf::Enumeration<std::string> headerNames =
request.getHeaderNames();