I know you've always thought about the trials and tribulations of experiencing the joys of life as a web proxy. Honestly, who hasn't? Today you're tasked with realizing this goal (at least a part of it). Website X gets a lot of traffic on the daily and is looking for a PaaS (clearly this refers to Proxy as a Service) because of the large number of users who insist on passing sensitive information via query parameters (users are silly). Your task is to remove any and all sensitive query parameters from the request before forwarding the request through to its original destination.
Input
- A well-formed absolute HTTP URL that follows the URI grammar in RFC3986 Section 3.
- You can assume there is no fragment
- Brief format example where anything in square brackets denotes optional:
http[s]://[user:pass@]host.name.com[:port]/[?param1=value1¶m2=value2...]
- A list of query parameters to be removed.
Output
The modified HTTP URL without the parameters defined in the input list.
Examples
http://example.com/ [foo]
> http://example.com/
http://example.com/?foo=bar []
> http://example.com/?foo=bar
http://example.com/ []
> http://example.com/
http://example.com/?foo=1&bar=2&baz=3 [foo,baz]
> http://example.com/?bar=2
http://example.com/?foo=1&bar=2&baz=3 [foo,bar,baz]
> http://example.com/
http://example.com/?foo&bar=2&baz= [foo,baz]
> http://example.com/?bar=2
http://example.com/?abc=1&def=2&baz=foo [foo,bar]
> http://example.com/?abc=1&def=2&baz=foo
http://example.com/?foobar=baz [foo]
> http://example.com/?foobar=baz
http://foo:[email protected]:8080/?foo=1&bar=foo [foo]
> http://foo:[email protected]:8080/?bar=foo
Scoring
This is code-golf, so the shortest answer (in bytes) wins.
&
appear anywhere other than between parameters? \$\endgroup\$?
? Also should the order be kept like it was? \$\endgroup\$&
is part of a query parameter it should be correctly urlencoded as%26
\$\endgroup\$http://foo:&[email protected]:8080/?foo=1&bar=foo
is allowed by the RFC. This should break a bunch of the existing solutions. :D (The rule is userinfo can be expanded as unreserved or pct-escape or sub-delims, and sub-delims can have&
and=
) \$\endgroup\$