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:

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

  1. 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.

  1. #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):

  1. WCCOAui1:["Mapping:"][mapping 7 items

  2. WCCOAui1: "DNT" : "1"

  3. WCCOAui1: "Accept-Language" : "de-AT"

  4. WCCOAui1: "User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

  5. WCCOAui1: "Connection" : "Keep-Alive"

  6. WCCOAui1: "Accept-Encoding" : "gzip, deflate"

  7. WCCOAui1: "Accept" : "text/html, application/xhtml+xml, */*"

  8. WCCOAui1: "Host" : "localhost:8080"

  9. WCCOAui1:]

Assignment

CTRL PlugIn

Availability

CTRL