apache / trafficserver

Apache Traffic Server™ is a fast, scalable and extensible HTTP/1.1 and HTTP/2 compliant caching proxy server.
https://trafficserver.apache.org/
Apache License 2.0
1.8k stars 793 forks source link

Using remap plugins for regex matches in the regex_remap plugin #9389

Open bhaveshpun opened 1 year ago

bhaveshpun commented 1 year ago

We're currently using ATS v8.1.1. To support regular expressions in request paths, we've been trying to use the regex_remap plugin in the mapping rules

Our remap rules look like this:

map https://example.com/.*.mp4 https://example.com/.*.mp4 @action=allow @method=get \
@plugin=regex_remap.so @pparam=maps.reg \
@plugin=url_sig.so @pparam=url_sig.config @pparam=pristineurl \
@plugin=compress.so @pparam=example.config \

map https://example.com/ https://example.com/ @action=allow @method=post @method=get \
@plugin=regex_remap.so @pparam=maps.reg \

Rules in the maps.reg file are defined in the following way:

^/.*mp4 $s://$f/$0

We would want to use the signed url plugin, the compression plugin and the allowed methods defined in the .*mp4 mapping rule on requests that match the .*mp4 regex.

For example, requests of the type https://example.com/abc.mp4 should be signed and only get method should be allowed for them.

With the current configurations, https://example.com/abc.mp4 matches the second mapping rule. Post method is allowed for such a request, signed urls are not required and compression isn't supported as well.

Is there a way in which we can enable the use of different remap plugins for different regex rules in the maps.reg file ? Or is there a simpler workaround for requests to match mapping rules containing regex quantifiers ?

zwoop commented 1 year ago

You can't match on regular expressions like that on the path, so in your case, everything matches the second "map" rule. There's also no way to control different plugins to be run based on the path like that either, the regex_remap plugin does not support that.

I don't know that there's any solution here which would allow you to run the remap plugins conditionally like this.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community.