Forum Discussion

Ken_Wong_48678's avatar
Ken_Wong_48678
Historic F5 Account
Jun 14, 2006

insert http header in tcp payload

Hi,

 

 

For some reasons, I need to insert a http header before LTM start to inspect http header and content. So, I try to insert the header in client data.

 

 

I can insert a header at the 0 offset using below irule, but I do not know how to insert in the middle of the payload. Is there anyone know how to get the offset in the payload? Thanks in advanced

 

 

Regards,

 

Ken

 

 

 

when CLIENT_ACCEPTED {

 

TCP::collect

 

}

 

 

when CLIENT_DATA {

 

TCP::payload replace 0 0 "header: value "

 

set new_pl [TCP::payload]

 

log local0. "new_pl"

 

TCP::release

 

}

 

1 Reply

  • A bit late, but...

    I was trying to figure out how to insert a Content-length header in the TCP response data before TMM processed the HTTP headers. I came up with the following which seems to work:

    
    when HTTP_REQUEST {
        if it's a HEAD request, set a variable to reference in SERVER_DATA event
       if { [HTTP::method]=="HEAD" }{
          set request_is_head 1
          log local0. "head"
       }
    }
    when SERVER_CONNECTED {
        if request was a head, collect the TCP data
       if { [info exists request_is_head] and $request_is_head==1 }{
          log local0. "collecting"
          TCP::collect 15
       }
    }
    when SERVER_DATA {
        if request was a head, insert a content-length header with a value of 0
       if { [info exists request_is_head] and $request_is_head==1 }{
          log local0. "payload before: [TCP::payload]"
          log local0. "index: [string first "\r\n\r\n" $server_payload]"
          TCP::payload replace [string first "\r\n\r\n" [TCP::payload]] 0 "\r\nContent-length: 0" 
          log local0. "payload after: [TCP::payload]"
       }
    }

    Aaron