httpGetAllHeaders()
The function returns a mapping of all HTTP headers.
Synopsis
mapping httpGetAllHeaders(int idx);
Parameter
Parameter | Description |
---|---|
idx | Idx is the client index that was specified as last argument in the callback function - see example below. The client index is an internal number of the client. |
Return value
A mapping of all HTTP headers.
Error
Errors can be queried with getLastError(). Errors can be:
-
Too few arguments
-
No httpServer() is installed
Description
The function returns a mapping of all HTTP headers where the key is always the header name and the value is the value for the key.
Example
-
The following example returns a mapping of all headers where the key is always the header name and the value is the value for the key. It checks if "linux" or "windows" are found in the "User-Agent" key.
-
#uses "CtrlHTTP" main() { httpServer(false, 8080, 0); httpConnect("example", "/"); } string example(dyn_string names, dyn_string values, string user, string ip,dyn_string headerNames, dyn_string headerValues, int idx) { mapping m = httpGetAllHeaders(idx); if ( !mappingHasKey(m, "User-Agent") ) return "unknown OS"; string ua = strtolower(m["User-Agent"]); DebugN("Header mapping:", m); if ( strpos(ua, "linux") != -1 ) return "OS detected as Linux"; else if ( strpos(ua, "windows") != -1 ) return "OS detected as Windows"; else return "unknown OS"; }
The function httpGetAllHeaders returns, e.g., the following data (Debug output):
-
WCCOAui1:["Mapping:"][mapping 7 items
-
WCCOAui1: "DNT" : "1"
-
WCCOAui1: "Accept-Language" : "de-AT"
-
WCCOAui1: "User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
-
WCCOAui1: "Connection" : "Keep-Alive"
-
WCCOAui1: "Accept-Encoding" : "gzip, deflate"
-
WCCOAui1: "Accept" : "text/html, application/xhtml+xml, */*"
-
WCCOAui1: "Host" : "localhost:8080"
-
WCCOAui1:]
Assignment
CTRL PlugIn
Availability
CTRL