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.
