You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by Ezequiel Foncubierta <ez...@gmail.com> on 2015/02/18 15:35:32 UTC

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://web.server:8080 @plugin=header_rewrite.so @pparam=rules.conf
reverse_map http://web.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:~/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:~/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.

Re: Header rewrite rule based on query string

Posted by Ezequiel Foncubierta <ez...@gmail.com>.
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 <su...@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 <su...@yahoo-inc.com>
> To: "users@trafficserver.apache.org" <us...@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 <ez...@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 <ma...@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 <ma...@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.
> 
> 
> 


Re: Header rewrite rule based on query string

Posted by Sudheer Vinukonda <su...@yahoo-inc.com>.
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} =TRUEadd-header TestHeader 1234 [L]
%cat remap.configmap http://cache.server:8080 http://web.server:8080 @plugin=header_rewrite.so @pparam=rules.config      From: Sudheer Vinukonda <su...@yahoo-inc.com>
 To: "users@trafficserver.apache.org" <us...@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} =TRUEadd-header TestHeader 1234 [L]
%cat remap.configmap http://cache.server:8080 http://web.server:8080 @plugin=header_rewrite.so @pparam=rules.config

Thanks,
Sudheer

 

     From: Ezequiel Foncubierta <ez...@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://web.server:8080 @plugin=header_rewrite.so @pparam=rules.conf
reverse_map http://web.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:~/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:~/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.

   

  

Re: Header rewrite rule based on query string

Posted by Sudheer Vinukonda <su...@yahoo-inc.com>.
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} =TRUEadd-header TestHeader 1234 [L]
%cat remap.configmap http://cache.server:8080 http://web.server:8080 @plugin=header_rewrite.so @pparam=rules.config

Thanks,
Sudheer

      From: Ezequiel Foncubierta <ez...@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://web.server:8080 @plugin=header_rewrite.so @pparam=rules.conf
reverse_map http://web.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:~/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:~/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.

  

Re: Header rewrite rule based on query string

Posted by Shu Kit Chan <ch...@gmail.com>.
Does this work? i.e. Have you tried this combination yet?

rules.conf
=====
cond %{SEND_RESPONSE_HDR_HOOK}
cond %{QUERY} /(^|&)a=true(&|$)/
add-header TestHeader 1234

plugin.config
=====
header_rewrite.so rules.conf

Thanks.

Kit



On Wed, Feb 18, 2015 at 6:35 AM, Ezequiel Foncubierta <
ezequiel.foncubierta@gmail.com> wrote:

> 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://web.server:8080
> @plugin=header_rewrite.so @pparam=rules.conf
> reverse_map http://web.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:~/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:~/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.