trafficserver-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ezequiel Foncubierta <ezequiel.foncubie...@gmail.com>
Subject Re: Header rewrite rule based on query string
Date Thu, 19 Feb 2015 08:42:44 GMT
Hi,

It works even with the READ_REQUEST_HOOK! Kudos to you sir. Just to understand what is going
on as there is not much documentation about this.

1. We are adding a header in the client request header if the query parameter is present.
> cond %{QUERY} /(^|&)a=true(&|$)/
> add-header @QueryPresent TRUE [L]


2. Check wether the flag (@QueryPresent) exists in the client request header.
> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
> cond %{CLIENT-HEADER:@QueryPresent} =TRUE
> add-header TestHeader 1234 [L]

is that correct?

Thank you so much!

Best regards.

> On 18 Feb 2015, at 20:17, Sudheer Vinukonda <sudheerv@yahoo-inc.com> wrote:
> 
> Sorry, the hook name READ_REQUEST_HOOK is incorrect - the below config is sufficient
(as this is being added on a remap hook anyway).
> 
> % cat rules.config 
> cond %{QUERY} /(^|&)a=true(&|$)/
> add-header @QueryPresent TRUE [L]
> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
> cond %{CLIENT-HEADER:@QueryPresent} =TRUE
> add-header TestHeader 1234 [L]
> 
> %cat remap.config
> map http://cache.server:8080  <http://cache.server:8080/>http://web.server:8080
<http://web.server:8080/> @plugin=header_rewrite.so @pparam=rules.config
> From: Sudheer Vinukonda <sudheerv@yahoo-inc.com>
> To: "users@trafficserver.apache.org" <users@trafficserver.apache.org> 
> Sent: Wednesday, February 18, 2015 10:50 AM
> Subject: Re: Header rewrite rule based on query string
> 
> The below config seems to do what you need:
> 
> % cat rules.config 
> cond %{READ_REQUEST_HOOK} [AND]
> cond %{QUERY} /(^|&)a=true(&|$)/
> add-header @QueryPresent TRUE [L]
> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
> cond %{CLIENT-HEADER:@QueryPresent} =TRUE
> add-header TestHeader 1234 [L]
> 
> %cat remap.config
> map http://cache.server:8080  <http://cache.server:8080/>http://web.server:8080
<http://web.server:8080/> @plugin=header_rewrite.so @pparam=rules.config
> 
> 
> Thanks,
> 
> Sudheer
> 
> 
> 
> 
> From: Ezequiel Foncubierta <ezequiel.foncubierta@gmail.com>
> To: users@trafficserver.apache.org 
> Sent: Wednesday, February 18, 2015 6:35 AM
> Subject: Header rewrite rule based on query string
> 
> Hi,
> 
> I am trying to rewrite the response header using the header_rewrite.so plugin.
> 
> My remap.config file:
> map http://cache.server:8080  <http://cache.server:8080/>http://web.server:8080
 <http://web.server:8080/>@plugin=header_rewrite.so @pparam=rules.conf
> reverse_map http://web.server:8080  <http://web.server:8080/>http://cache.server:8080
<http://cache.server:8080/>
> 
> My rules.conf file:
> cond %{SEND_RESPONSE_HDR_HOOK}
> cond %{QUERY} /(^|&)a=true(&|$)/
> add-header TestHeader 1234
> 
> What I am expecting with this configuration so far is that if the request URL has a query
parameter "a=true”, then the TestHeader 1234 will be added to the response header. However,
I get the following message in the debug traces.
> 
> vagrant@cache <mailto:vagrant@cache>:~/trafficserver$ sudo traffic_server -T"header"
> traffic_server: using root directory '/usr/local'
> traffic_server: using root directory '/usr/local'
> [Feb 18 14:05:04.450] Server {0x7fd4f5454740} DIAG: (header_rewrite) Remap plugin is
successfully initialized
> [Feb 18 14:05:04.451] Server {0x7fd4f5454740} DIAG: (header_rewrite) Instantiating a
new remap.config plugin rule
> [Feb 18 14:05:04.451] Server {0x7fd4f5454740} DIAG: (header_rewrite) Loading remap configuration
file rules.conf
> [Feb 18 14:05:04.451] Server {0x7fd4f5454740} DIAG: (header_rewrite)    Adding condition:
%{QUERY} with arg: /(^|&)a=true(&|$)/
> [Feb 18 14:05:04.452] Server {0x7fd4f5454740} DIAG: (header_rewrite) Regex precompiled
successfully
> [Feb 18 14:05:04.452] Server {0x7fd4f5454740} DIAG: (header_rewrite)    Adding operator:
add-header(TestHeader)
> [Feb 18 14:05:04.452] Server {0x7fd4f5454740} DIAG: (header_rewrite) Succesfully loaded
remap config file rules.conf
> [Feb 18 14:05:04.453] Server {0x7fd4f5454740} DIAG: (header_rewrite) Adding remap ruleset
to hook=TS_HTTP_SEND_RESPONSE_HDR_HOOK
> [Feb 18 14:05:23.841] Server {0x7fd4f1819700} DIAG: (header_rewrite) Added remapped TXN
hook=TS_HTTP_SEND_RESPONSE_HDR_HOOK
> [Feb 18 14:05:23.841] Server {0x7fd4f1819700} DIAG: (header_rewrite) Building resources,
hook=(null)
> [Feb 18 14:05:23.841] Server {0x7fd4f1819700} DIAG: (header_rewrite)     Adding TXN client
request header buffers
> [Feb 18 14:05:23.841] Server {0x7fd4f1819700} DIAG: (header_rewrite)     Adding TXN client
request header buffers for remap instance
> [Feb 18 14:05:23.896] Server {0x7fd4f1819700} DIAG: (header_rewrite) Building resources,
hook=TS_HTTP_SEND_RESPONSE_HDR_HOOK
> [Feb 18 14:05:23.896] Server {0x7fd4f1819700} DIAG: (header_rewrite)     Adding TXN client
request header buffers
> [Feb 18 14:05:23.896] Server {0x7fd4f1819700} DIAG: (header_rewrite)     Adding TXN client
response header buffers
> [Feb 18 14:05:23.896] Server {0x7fd4f1819700} DIAG: (header_rewrite) QUERY requires remap
initialization! Evaluating to false!
> 
> If I get rid of the SEND_RESPONSE_HDR_HOOK condition in rules.conf, I get the following
traces:
> 
> vagrant@cache <mailto:vagrant@cache>:~/trafficserver$ sudo traffic_server -T"header"
> traffic_server: using root directory '/usr/local'
> traffic_server: using root directory '/usr/local'
> [Feb 18 14:09:49.061] Server {0x7f7d6d42f740} DIAG: (header_rewrite) Remap plugin is
successfully initialized
> [Feb 18 14:09:49.061] Server {0x7f7d6d42f740} DIAG: (header_rewrite) Instantiating a
new remap.config plugin rule
> [Feb 18 14:09:49.061] Server {0x7f7d6d42f740} DIAG: (header_rewrite) Loading remap configuration
file rules.conf
> [Feb 18 14:09:49.061] Server {0x7f7d6d42f740} DIAG: (header_rewrite)    Adding condition:
%{QUERY} with arg: /(^|&)a=true(&|$)/
> [Feb 18 14:09:49.061] Server {0x7f7d6d42f740} DIAG: (header_rewrite) Regex precompiled
successfully
> [Feb 18 14:09:49.062] Server {0x7f7d6d42f740} DIAG: (header_rewrite)    Adding operator:
add-header(TestHeader)
> [Feb 18 14:09:49.062] Server {0x7f7d6d42f740} DIAG: (header_rewrite) Succesfully loaded
remap config file rules.conf
> [Feb 18 14:09:55.967] Server {0x7f7d697f4700} DIAG: (header_rewrite) Building resources,
hook=(null)
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite)     Adding TXN client
request header buffers
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite)     Adding TXN client
request header buffers for remap instance
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite) Appending QUERY
to evaluation value: a=true
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite) Evaluating QUERY
- a=true
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite) Test regular expression
(^|&)a=true(&|$) : a=true
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite) Successfully found
regular expression match
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite) OperatorAddHeader::exec()
invoked on header TestHeader: 1234
> [Feb 18 14:09:55.968] Server {0x7f7d697f4700} DIAG: (header_rewrite)    Adding header
TestHeader
> 
> The regular expression is working as it is expected for the QUERY condition but, obviously,
the TestHeader is added to the HTTP request from cache.server to web.server instead of the
HTTP response from cache.server to the client. On the other hand, the PATH condition works
nicely with the SEND_RESPONSE_HDR_HOOK condition.
> 
> I have tried many different configuration with no luck (i.e. setting the plugin in plugin.config).
Any help would be really appreciated.
> 
> Thank you!
> 
> Best regards.
> 
> 
> 


Mime
View raw message