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):

> [timwolla@~]begin
>                 nc -l 127.0.0.1 8082 &
>                 curl -q localhost:8080/foo/1234.png
>                 wait
>                 echo ============
>                 nc -l 127.0.0.1 8082 &
>                 curl -q localhost:8081/foo/1234.png
>                 wait
>             end
> GET /12/34 HTTP/1.1
> host: localhost:8080
> user-agent: curl/7.47.0
> accept: */*
> fe: 1
> 
> <html><body><h1>504 Gateway Time-out</h1>
> The server didn't respond in time.
> </body></html>
> ============
> GET /12/34 HTTP/1.1
> host: localhost:8081
> user-agent: curl/7.47.0
> accept: */*
> fe: 2
> Connection: close
> 
> <html><body><h1>504 Gateway Time-out</h1>
> The server didn't respond in time.
> </body></html>

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.

Best regards
Tim Düsterhus

Reply via email to