Getting HTTP Headers
The headers of the original HTTP request object contain information about the request such as the host, connection, and cache control headers. In addition, client app developers can add custom HTTP headers to the data request so that module developers can have additional information about the request.
The following example shows a snippet of Java code for an Android application that sets an HTTP header on the request:
In a custom module, you access the HTTP request headers by using the
getHeader()method takes a string (the header name), and returns an object (the header). When you get the value of the header, you typically cast the result to a String.
getHeaders()method returns a Map that you can then use to access the header values.
The following example gets a single HTTP request header, and also gets all headers and adds them to the body of the response:
You can also use the AKRequest object's
getHeader() method to get the value of a single header in your custom module. This method returns the specified header value as a List.
In addition to the
getHeaders() methods, you can also use the AKRequest object's convenience methods for accessing information about the request, such as the content type, character set, accept types, and request method. The following example uses several of these convenience methods:
In the last module in the route, you might want to set the values of some of the HTTP headers. To do this, you use the AKMessage class's
setHeaders() methods. For more information, see Setting HTTP Headers on the Response.
For additional information about how a client app developer can set HTTP headers in a data request, see Remote Data Access from Android and iOS Clients.