Forum Discussion

Yugandhar's avatar
Yugandhar
Icon for Nimbostratus rankNimbostratus
Mar 07, 2019

iRule to Collect the HTTP Header Values into an Array.

Hi,

Can we have an iRule to collect all the HTTP Header values in an array and send that info to a remote log server.

when HTTP_REQUEST {

foreach RequestHeader [HTTP::header names] {

set RequestHeaderName($RequestHeader) [HTTP::header value $RequestHeader]   Assigning the Header Values to an Array 

}

set LogInfo "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri] ---> [array get RequestHeaderName]"

log local0 10.10.10.10 "$LogInfo"

}

when HTTP_RESPONSE {

foreach ResponseHeader [HTTP::header names] {

set ResponseHeaderName($ResponseHeader) [HTTP::header value $ResponseHeader]   Assigning the Header Values to an Array 

}

set LogInfo "Response from Server [IP::remote_addr]:[TCP::remote_port] ---> [array get ResponeHeaderName]"

log local0 10.10.10.10 "$LogInfo"

}

Thanks,

Yugandhar.

  • when HTTP_REQUEST {
        set logEntry ""
        foreach headerName [HTTP::header names] {
            append logEntry "$headerName:[HTTP::header value $headerName]"
        }
        log local0 10.10.10.10 "$LogEntry
    }
    

    How about this? It doesn't actually create an array but it prints out the header names and values which seems to be what you want. You may find that the log entry is too large.

    There are arrays in tcl but they are not very easy to use. You can use lists as well.