Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active March 5, 2017 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnetikonline/fd5142fe54096c41790473f53825d69b to your computer and use it in GitHub Desktop.
Save magnetikonline/fd5142fe54096c41790473f53825d69b to your computer and use it in GitHub Desktop.
NetScaler rewrite action to update a cookie key value.

NetScaler rewrite action to update a cookie key value

Making a note of this because NetScalers at just awful at anything when it comes to messing with HTTP header cookie values.

So I wish to update the value of a Cookie key of mykey= to mykey=new_value. I can do so with the following rewrite action:

  • Type: REPLACE

  • Expression to choose target location: HTTP.REQ.HEADER("Cookie")

  • Expression:

     (HTTP.REQ.HEADER("Cookie").BEFORE_STR("; mykey=") + ("; " + HTTP.REQ.HEADER("Cookie")).AFTER_REGEX(re#; mykey=[^;]*#) + "; mykey=new_value").STRIP_START_CHARS("; ")
    

This will replace a key at the start, middle or end of a cookie string.

Painful? Yes. Useful? Somewhat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment