Re: Set header with value extracted from path

2014-12-04 Thread Baptiste
On Thu, Dec 4, 2014 at 12:09 AM, Ryan rnidef...@gmail.com wrote:
 When I received URL's with the following format:

 /1/a/b/c

 I rewrite the URL removing the digit like so:

 /v2.0.0/a/b/c

 And I need to set a header with the value of the digit I replaced, i.e.:

 X-ID: 1

 Is it possible to do this within haproxy? I am able to reqrep the original
 url, and set an ACL to be used with an http-request add-header directive,
 but I dont know how to extract the url value and either save it for use in
 the add-header, or to write a format string in the add-header directive that
 will do this.

 I'm playing around with something like this but not having much luck:

 acl url_id path_reg ^/([0-9]+)/.*$
 http-request add-header X_ID %[path_reg(^/([0-9]+)/.*$)] if url_id

 Any ideas?

 Thanks,
 Ryan



Hi Rian,

Either there is a bug in the code or the documentation is inacurate,
in chapter 7.3.6 HTTP samples.
The document says we can fetch content using a sample called path and
all its derivatives, including path_reg.

Actually, when I add the following in my conf:
  http-request set-header X-blah %[path_reg .*]
I have a configuration parsing error because of the slash.
When I backslash it:
 http-request set-header X-blah %[path_reg\ .*]
The configuration is valid (from a syntax point of view) but HAProxy
doesn't do anything.


So in your case, I would do this for now:
 acl url_id path_reg ^/([0-9]+)/.*$
 http-request set-header X_ID %[path] if url_id
 http-request replace-value X_ID ^/([0-9]+)/.*$ \1 if { req.hdr(X_ID) -m found }

should do the trick.

Baptiste



Set header with value extracted from path

2014-12-03 Thread Ryan
When I received URL's with the following format:

/1/a/b/c

I rewrite the URL removing the digit like so:

/v2.0.0/a/b/c

And I need to set a header with the value of the digit I replaced, i.e.:

X-ID: 1

Is it possible to do this within haproxy? I am able to reqrep the original
url, and set an ACL to be used with an http-request add-header directive,
but I dont know how to extract the url value and either save it for use in
the add-header, or to write a format string in the add-header directive
that will do this.

I'm playing around with something like this but not having much luck:

acl url_id path_reg ^/([0-9]+)/.*$
http-request add-header X_ID %[path_reg(^/([0-9]+)/.*$)] if url_id

Any ideas?

Thanks,
Ryan