Replace/Clear X-Forwarded-4 or insert if not existent

rportelarportela Member
Hello,

We're using the following script to insert an XFF header.

when HTTP_REQUEST {
HTTP::header insert "X-Forwarded-For" [IP::client_addr]
}


How do I change it to SET (not insert) a single header ?
I mean if there is already an XXF, we want to clear it....before inserting our own.

Thank you

Comments

  • diederikdiederik Member
    edited November 2015
    Hello,

    You can do this when using:
    HTTP::header [value] <name> <string>
    
    Sets the value of the named header. If the header is present, the command replaces the header; otherwise, the com- mand adds the header. You can omit the <value> argument if the header name does not collide with any other val- ues.



    And make it:
    when HTTP_REQUEST {
    HTTP::header “X-Forwarded-For” [IP::client_addr]
    }
    
  • rportelarportela Member
    edited November 2015
    Great. Working !!!

    Thank you....
  • diederikdiederik Member
    edited November 2015
    On addition.

    If there is a chance there are multiple instances of the same header, the HTTP:header command will only overwrite one.

    You need to use "HTTP:header remove" first to remove all instances of that header.
    Before you add a new one or insert one.
Sign In or Register to comment.