Hi Matt,

[ please avoid top-posting, it's very unconvenient to reply with the context,
  rearranging your mail now ]

On Wed, May 28, 2014 at 11:40:55PM +0200, Matt . wrote:
> 2014-05-28 23:28 GMT+02:00 Bryan Talbot <bryan.tal...@playnext.com>:
> > The example in the "reqirep" section of the documentation seems to mostly do
> > what you're asking.
> >
> >
> > http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#reqirep
> >
> > Does that not work?
> >
> > This will rewrite "foo.com/baz.jpg" -> "newdomain.com/com/foo/baz.jpg"
> >
> >   reqirep ^Host:\ foo.com Host:\ newdomain.com
> >   reqirep ^GET\ /(.*) GET\ /com/foo/\1
> 
> Yes I cam up to that part, but about the search in the map, do I need
> to do this twice ?

You could. In fact there's a trick you could use now which consists in
using the "base" sample as a key for two maps. "base" contains the
concatenation of the host name and the URI. For example :

   GET /foo/bar HTTP/1.1
   Host: blah.example.org

Then "base" will equal "blah.example.org/foo/bar". I think you see
where I'm going now. You can simply build two maps, one for the
uri part and one for the Host part, both indexed on the base, and
retrieve each part from there.

Hmmm thinking a bit more about it, I'm seeing an issue here. I don't
see how I could replace part of a URI using sample fetch expressions :-(

Well, if you don't have too many URIs to replace, you could at least apply
them based on a condition (eg: if you only need to insert a few prefixes,
you could simply condition a few reqirep rule on the output of the URI map).

For example it could be more or less like this :

    reqirep ^GET\ /(.*) GET\ /foo/\1 if { base,map(prefix.map) foo }
    reqirep ^GET\ /(.*) GET\ /bar/\1 if { base,map(prefix.map) bar }
    reqirep ^GET\ /(.*) GET\ /com/\1 if { base,map(prefix.map) com }
    http-request set-header Host %[base,map(host.map)]

There will be a few tricks that might be needed (basically, the "base" for
setting the Host header will change due to the former rewrite), but before
going into details, I'd need to know if you think this is something that
could be acceptable.

Regards,
Willy


Reply via email to