goproxy icon indicating copy to clipboard operation
goproxy copied to clipboard

Added CookieMatches for Cookie matching on requests

Open BBerastegui opened this issue 9 years ago • 6 comments

With CookieMatches you will be able to trigger any behaviour if you find regexp matches against some particular cookie pattern.

BBerastegui avatar Jan 19 '16 04:01 BBerastegui

Hi,

Thanks for the PR.

I'm not sure if matching against the cookie representation is a good idea. I'd add a way to match against a certain cookie's key. So that we'd match a regexp against specific Cookie(key).Value.

elazarl avatar Jan 19 '16 08:01 elazarl

Hi !

In my case, I was trying to find a regexp matching cookie being sent in the request and then modifying/deleting/triggering whatever behaviour we wanted.

That is why I decided to add the same functionality as:

func ReqHostMatches(regexps ...*regexp.Regexp) ReqConditionFunc

We can add also something more strict as you propose. Something like "CookieIs" as in the host-related function, but based on the cookie key and/or value:

func ReqHostIs(hosts ...string) ReqConditionFunc

BBerastegui avatar Jan 19 '16 08:01 BBerastegui

Didn't you know in advance which key would the cookie contain?

On Tue, Jan 19, 2016 at 10:29 AM, Borja Berastegui <[email protected]

wrote:

Hi !

In my case, I was trying to find a regexp matching cookie being sent in the request and then modifying/deleting/triggering whatever behaviour we wanted.

That is why I decided to add the same functionality as:

func ReqHostMatches(regexps ...*regexp.Regexp) ReqConditionFunc

We can add also something more strict as you propose. Something like "CookieIs" as in the host-related function, but based on the cookie key and/or value:

func ReqHostIs(hosts ...string) ReqConditionFunc

— Reply to this email directly or view it on GitHub https://github.com/elazarl/goproxy/pull/141#issuecomment-172774392.

elazarl avatar Jan 19 '16 08:01 elazarl

In my specific case yes, one key in particular.

But in the case that the key might be variable (I've seen several applications doing this), it will be great to be able to match it using a regexp.

BBerastegui avatar Jan 19 '16 08:01 BBerastegui

In this case we should give two regexp, for the key and for the value.

This would avoid all the key escaping problems.

On Tue, Jan 19, 2016 at 10:42 AM, Borja Berastegui <[email protected]

wrote:

In my specific case yes, one key in particular.

But in the case that the key might be variable (I've seen several applications doing this), it will be great to be able to match it using a regexp.

— Reply to this email directly or view it on GitHub https://github.com/elazarl/goproxy/pull/141#issuecomment-172776690.

elazarl avatar Jan 19 '16 09:01 elazarl

So, two separate functions like:

func CookieKeyMatches(regexps ...*regexp.Regexp) ReqConditionFunc

And:

func CookieValueMatches(regexps ...*regexp.Regexp) ReqConditionFunc

Or one function with two parameters:

func CookieMatches(regexpKey *regexp.Regexp, regexpValue *regexp.Regexp) ReqConditionFunc

Or:

func CookieMatches(regexpKey *regexp.Regexp, regexpValue *regexp.Regexp) ReqConditionFunc

?

BBerastegui avatar Jan 20 '16 00:01 BBerastegui