Forum Discussion

Sekhar's avatar
Sekhar
Icon for Nimbostratus rankNimbostratus
Mar 25, 2015

Capturing HTTP Header Info

Hi,

 

Please help me out in capturing the HTTP header info when a server is sending data to external client through F5.

 

Sample info:

 

content-length:2756

 

-----------------------------B8C4CFF62AF14 Content-Disposition: form-data; name="from"

 

111111111 -----------------------------B8C4CFF62AF14 Content-Disposition: form-data; name="to"

 

Thanks,

 

Sekhar

 

2 Replies

  • THi's avatar
    THi
    Icon for Nimbostratus rankNimbostratus

    Depends on what you want to get and use the header data for. You could use an iRule to capture the headers from the server response, for example:

    when HTTP_RESPONSE {
      foreach hdr [HTTP::header names] {
        log local0. "HTTP Header : $hdr = [HTTP::header values $hdr]"
        }
    }
    

    will produce log lines in /var/log/ltm, similar like this:

    Mar 25 22:18:19 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Content-Length = 1293
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Content-Type = text/html
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Content-Encoding = gzip
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Last-Modified = {Fri, 10 Feb 2012 06:48:40 GMT}
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Accept-Ranges = bytes
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : ETag = {"094905c0e7cc1:0"}
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Vary = Accept-Encoding
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Server = Microsoft-IIS/7.0
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : X-Powered-By = ASP.NET
    Mar 25 22:18:40 apmlab1 info tmm1[11675]: Rule /timo/test_hdr_iRule : HTTP Header : Date = {Wed, 25 Mar 2015 20:18:40 GMT}
    

    This is just for reference, so modify to suit your needs and attach your iRule to your virtual server as a resource in addition to the server pool.

    Note that the foreach -loop will produce multiple occurrences of same log line if there are multiple occurrences of the same header name. HTTP::header values -command will list all values of the same header name in this case.

  • The easiest way is to assign a HTTP profile to your virtual server so you can make use of the HTTP parser and helper commands. Here's a CodeShare entry that logs all request and response headers in an HTTP connection

     

    https://devcentral.f5.com/wiki/iRules.LogHttpHeaders.ashx

     

    If you can't use an HTTP profile, you'll need to use the TCP::payload command to get the full content and then write some string processing to pull the values out.

     

    -Joe