Hi Tim, On Wed, May 15, 2019 at 05:09:31PM +0200, Tim Düsterhus wrote: > Willy, > > Am 15.05.19 um 11:31 schrieb Tim Düsterhus: > >>> 2. 'req*' and 'rsp*'. I remember that they allow some modification that > >>> cannot easily be replicated otherwise (but I'll have to check that > >>> first). > >> > >> Sure but practically speaking such modifications do not make sense in > >> the real world (e.g. rename many header names at once). And the "excuse" > > > > I believe it was some kind of request path rewriting that was not easily > > possibly with `http-request set-path` (maybe because of syntax > > limitations). I'll definitely check and report back. > > > > Okay, I looked it up. It's simple: Everything that needs capturing > groups for the path modifications is not exactly trivial or clean to > replicate otherwise (but it's possible as I found out by scrolling > through the docs and seeing http-request replace-header): > > Consider I have URLs in a folder that I want to map to "git object > directory style" hashed folders (that's a hypothetical example, but I've > used something similar in production): > > /foo/1234.png will become /12/34 > > This is my config: > > > defaults > > timeout server 1s > > mode http > > option httpclose > > > > listen fe > > bind :8080 > > reqrep ^([^\ :]*)\ /foo/(.{2})(.*).png \1\ /\2/\3 > > http-request set-header FE 1 > > > > server example localhost:8082 > > > > listen fe2 > > bind :8081 > > http-request set-header XXX %[path] > > http-request replace-header XXX /foo/(.{2})(.*).png /\1/\2 > > http-request set-path %[req.hdr(XXX)] > > http-request del-header XXX > > http-request set-header FE 2 > > > > server example localhost:8082 > > Both frontends will do the correct replacement, but IMO the reqrep one > is more readable (not that any of these are really readable):
I'm having a different view on this. The one using the headers hack is horrible while the reqrep one is simply ugly :-) Really, this is a good reason for having a "replace-uri" action. It should mostly be a copy-paste of the replace-header code but applied to the URI, and will be much simpler and safer to use than any of the tricks above. You'd then do : http-request replace-uri /foo/(.{2})(.*).png /\1/\2 instead of : reqrep ^([^\ :]*)\ /foo/(.{2})(.*).png \1\ /\2/\3 And more importantly it will respect the execution order related to other HTTP rules! > The obvious `http-request set-path %[path,regsub(...)]` as suggested in > the docs for `http-request set-query` does *NOT* work, because the > `regsub` parameters cannot contain the closing parenthesis required for > capture groups. Yep I see. I've added feature request #100 to keep track of this. I'm willing to merge this even late into 2.0 and to make sure we can warn on rsp/req*. Just let me know if you're interested. Also feel free to add replace-path to replace only the path component as I suspect it could be useful as well. Oh BTW I've merged your 6 patches into the "next" branch and merged two of them into master. thanks, Willy