Forum Discussion
Dec 04, 2015
Hi,
i like Stanislas approach (+1) but perhaps we have some more use cases to consider: * empty query, * parameter at the beginning of, middle of or end of query, * relevant parameter being the only parameter in query, * query separators might be ampersands or semicolons, * relevant parameter might not be case sensitive.(I got a similar request from a client a while ago and had to work through it. Please reply if you find the list incomplete or wrong.)
Here is my approach based on regsub allowing regex and not being case sensitive:when HTTP_REQUEST priority 100 {
if { [HTTP::query] ne "" } {
regsub -nocase -all {(^identity=[^;&]*[;&]?|[;&]identity=[^;&]*)} [HTTP::query] "" new_query
log local0. "no vars: [regsub -nocase -all {(^identity=[^;&]*[;&]?|[;&]identity=[^;&]*)} [HTTP::query] ""]"
log local0. "in: [HTTP::uri] | out: [HTTP::path]?$new_query"
if {$new_query ne ""} {
HTTP::uri [HTTP::path]?$new_query
HTTP::respond 200 content "[HTTP::path]?[HTTP::query]\n" noserver
} else {
HTTP::uri [HTTP::path]
HTTP::respond 200 content "[HTTP::path]\n" noserver
}
}
}
Uncomment lines in the iRule for local testing via cURL:
curl -v -0 "http://10.131.131.61/mypath?idenTity=0;p1=a;p2=b;identity=123;p3=c&Identity=456"
* About to connect() to 10.131.131.61 port 80 (0)
* Trying 10.131.131.61... connected
* Connected to 10.131.131.61 (10.131.131.61) port 80 (0)
> GET /mypath?idenTity=0;p1=a;p2=b;identity=123;p3=c&Identity=456 HTTP/1.0
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/1.0.1l zlib/1.2.3 libidn/0.6.5
> Host: 10.131.131.61
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Connection: close
< Content-Length: 23
<
/mypath?p1=a;p2=b;p3=c
Thanks, Stephan