In the manual [1] there is an example for using reqrep with syntax like this:

    # replace "/static/" with "/" at the beginning of any request path.
    reqrep ^([^\ :]*)\ /static/(.*)     \1\ /\2


But a typical http request looks like this:

    GET /haproxy-dconv/1.7/configuration.html HTTP/1.1
    Host: cbonte.github.io
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) 
Gecko/20100101 Firefox/53.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-GB,en;q=0.5
    Accept-Encoding: gzip, deflate, br
    DNT: 1
    Connection: keep-alive
    Upgrade-Insecure-Requests: 1
    Cache-Control: max-age=0


Firstly, is there no better/cleaner way to rewrite the path than this messy 
regex which seems to process all the http headers rather than just the request 
line that contains the path? And not only that, but we need to consume all 
three parts of that line including the HTTP version.

The ACL processing engine already can get at the path, so it is available 
somewhere inside haproxy, just not in a way we can easily rewrite.


Secondly, why was this particular regex used in the example? If I'm reading 
this correctly, quoting the string would simplify it to:

    reqrep '^([^ :]*) /static/(.*)'     '\1 /\2'

But is this even clearer and safer:

    reqrep '^([A-Z]+) /static(/.*)'     '\1 \2'

or narrow this down (where appropriate to the type of request) to

    reqrep '^(GET|POST) /static(/.*)'     '\1 \2'


Perhaps the example would be clearer like this (even though this is slower and 
not needed here, it is clearly demonstrating the point):

    reqrep '^(GET|POST) /static(/.*) (HTTP/.+)'     '\1 \2 \3'



Have I got all the above right? I'm finding examples on the internet like this 
[2] where the author believes the first part is the url scheme which I think is 
wrong.



Thanks
Ari





[1] https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-reqrep
[2] 
https://fromanegg.com/post/2014/12/05/how-to-rewrite-and-redirect-with-haproxy/

-- 
-------------------------->
Aristedes Maniatis
CEO, ish
https://www.ish.com.au
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to