Reputation: 61
I'm having a problem to ban a url inside Varnish (Version 6.0.2).
I'm trying to ban a url like this
/api/v2/product?param1=value1¶m2=value2param3=value3
If I give this command:
varnishadm ban req.url '~' '^/api/v2/product'
It works correctly but it bans all the urls that start with /api/v2/product
and I need to ban just that specific url.
These are the tries that I've done:
varnishadm ban req.url '~' '^/api/v2/product?param1=value1¶m2=value2param3=value3'
It doesn't return any error but it doesn't ban the url
varnishadm ban req.url '~' '^/api/v2/product\?param1=value1'
and I get this error:
Unknown request.
Type 'help' for more info.
Syntax Error: Invalid backslash sequence
Command failed with error code 100
varnishadm ban req.url '~' '^/api/v2/product[?]param1=value1'
or
varnishadm ban req.url '~' '^/api/v2/product\\?param1=value1'
It doesn't return any error but it doesn't ban the url
I've tried also without the Regex using the ==
varnishadm ban req.url '==' '/api/v2/product?param1=value1¶m2=value2param3=value3'
It doesn't return any error but it doesn't ban the url
I thought that the problem was the ?
so I tried to use the .*
instead of the ?
I've tried:
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1'
And it works, it bans all the urls that start with: ^/api/v2/product¶m1=value1
so I've tried
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1¶m2=value2'
It doesn't return any error but it doesn't ban the url, so I supected that the problem could be the &
this time so I've tried:
varnishadm ban req.url '~' '^/api/v2/product.*param1=value1.*param2=value2'
But nothing, it doesn't return errors but it doesn't ban that url.
Any attempt to escape the special character using the \ returns the error message:
Unknown request.
Type 'help' for more info.
Syntax Error: Invalid backslash sequence
Command failed with error code 100
Varnish manual says that the software uses PCRE standards, but I can't find a way to write a regex for it.
Any help or suggestions would be really appreciated.
Thanks H2K
Upvotes: 0
Views: 549
Reputation: 61
I've found the problem, there was a
set req.url = std.querysort(req.url);
inside the code that was altering the order of my get parameters invalidating the regex.
Upvotes: 1