Adding headers to 304 Responses

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding headers to 304 Responses

Mark Moseley
I've been perusing the code but not finding anything. Was hoping someone could give me a pointer where in the code I could add headers that ATS sends back with 304 Responses, if that's even possible. I want to add some custom headers (cf. apache httpd, in modules/http/http_filters.c line 1281).

Or even better yet, a configuration option that I haven't stumbled across yet :)
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

James Peach
On Nov 21, 2013, at 8:23 PM, Mark Moseley <[hidden email]> wrote:

> I've been perusing the code but not finding anything. Was hoping someone could give me a pointer where in the code I could add headers that ATS sends back with 304 Responses, if that's even possible. I want to add some custom headers (cf. apache httpd, in modules/http/http_filters.c line 1281).
>
> Or even better yet, a configuration option that I haven't stumbled across yet :)

You can do this using the header_rewrite plugins, see the example here <https://github.com/apache/trafficserver/tree/master/plugins/header_rewrite/Examples>. The documentation for this is *ahem* sparse, but if you poke zwoop on IRC he will help you out ...

J
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Igor Galić-2


----- Original Message -----

> On Nov 21, 2013, at 8:23 PM, Mark Moseley <[hidden email]> wrote:
>
> > I've been perusing the code but not finding anything. Was hoping someone
> > could give me a pointer where in the code I could add headers that ATS
> > sends back with 304 Responses, if that's even possible. I want to add some
> > custom headers (cf. apache httpd, in modules/http/http_filters.c line
> > 1281).
> >
> > Or even better yet, a configuration option that I haven't stumbled across
> > yet :)
>
> You can do this using the header_rewrite plugins, see the example here
> <https://github.com/apache/trafficserver/tree/master/plugins/header_rewrite/Examples>.
> The documentation for this is *ahem* sparse, but if you poke zwoop on IRC he
> will help you out ...

would be awesome if he could *help* you *fix* our documentation ;)


> J

--
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: [hidden email]
URL: http://brainsware.org/
GPG: 8716 7A9F 989B ABD5 100F  4008 F266 55D6 2998 1641

Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
In reply to this post by James Peach
On Thu, Nov 21, 2013 at 8:31 PM, James Peach <[hidden email]> wrote:
On Nov 21, 2013, at 8:23 PM, Mark Moseley <[hidden email]> wrote:

> I've been perusing the code but not finding anything. Was hoping someone could give me a pointer where in the code I could add headers that ATS sends back with 304 Responses, if that's even possible. I want to add some custom headers (cf. apache httpd, in modules/http/http_filters.c line 1281).
>
> Or even better yet, a configuration option that I haven't stumbled across yet :)

You can do this using the header_rewrite plugins, see the example here <https://github.com/apache/trafficserver/tree/master/plugins/header_rewrite/Examples>. The documentation for this is *ahem* sparse, but if you poke zwoop on IRC he will help you out ...

I was a bit vague (I shouldn't write emails after a long day). I should've included some details like: ATS 4.1.1 and that I'm trying to get ATS to add headers to its own 304 responses.

Giving headers_rewrite a try.

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-1 %{HEADER:X-From-Apache}

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-2 Hi

To test this, I created a dummy header called X-From-Apache that's getting added via .htaccess.

For a "Pragma: no-cache" request, ATS is indeed copying it over into X-ATS-1, along with just setting X-ATS-2. So far so good.

 > GET /test.html HTTP/1.1
> User-Agent: curl/7.30.0
> Accept: */*
> Pragma: no-cache
> Host: example.com
>
< HTTP/1.1 200 OK
< Date: Fri, 22 Nov 2013 18:42:13 GMT
< Content-Type: text/html
< Content-Length: 2
< Connection: keep-alive
< Server: Apache/2
< X-From-Apache: Hi from apache
< Last-Modified: Fri, 22 Nov 2013 18:41:52 GMT
< ETag: "2-4ebc85e219631"
< Accept-Ranges: bytes
< Cache-Control: max-age=3600
< Expires: Fri, 22 Nov 2013 19:42:13 GMT
< Vary: Accept-Encoding
< Age: 0
< X-ATS-1: Hi from apache
< X-ATS-2: Hi


For the conditional request though, ATS added that one explicit header but didn't copy over X-From-Apache:

> GET /test.html HTTP/1.1
> User-Agent: curl/7.30.0
> Accept: */*
> If-Modified-Since: Fri, 22 Nov 2013 18:41:52 GMT
> Host: example.com
>
< HTTP/1.1 304 Not Modified
< Date: Fri, 22 Nov 2013 18:42:36 GMT
< Connection: keep-alive
< Etag: "2-4ebc85e219631"
< Expires: Fri, 22 Nov 2013 19:42:13 GMT
< Cache-Control: max-age=3600
< Vary: Accept-Encoding
< X-ATS-2: Hi


If I send a non-conditional request (but without the Pragma: no-cache like in the first example), I get X-ATS-1 like in the Pragma: no-cache example. So 200 responses, whether cached or not cached, are getting the header copied over by headers_rewrite, just not in 304's.

Is the not copying headers for a 304 expected behavior or should I open a ticket about it?
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Shu Kit Chan
I think in your "conditional request" example, the response does not have a X-From-Apache header.
The code is done in such a way that it will ignore add-header if the value is empty.


On Fri, Nov 22, 2013 at 10:54 AM, Mark Moseley <[hidden email]> wrote:
On Thu, Nov 21, 2013 at 8:31 PM, James Peach <[hidden email]> wrote:
On Nov 21, 2013, at 8:23 PM, Mark Moseley <[hidden email]> wrote:

> I've been perusing the code but not finding anything. Was hoping someone could give me a pointer where in the code I could add headers that ATS sends back with 304 Responses, if that's even possible. I want to add some custom headers (cf. apache httpd, in modules/http/http_filters.c line 1281).
>
> Or even better yet, a configuration option that I haven't stumbled across yet :)

You can do this using the header_rewrite plugins, see the example here <https://github.com/apache/trafficserver/tree/master/plugins/header_rewrite/Examples>. The documentation for this is *ahem* sparse, but if you poke zwoop on IRC he will help you out ...

I was a bit vague (I shouldn't write emails after a long day). I should've included some details like: ATS 4.1.1 and that I'm trying to get ATS to add headers to its own 304 responses.

Giving headers_rewrite a try.

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-1 %{HEADER:X-From-Apache}

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-2 Hi

To test this, I created a dummy header called X-From-Apache that's getting added via .htaccess.

For a "Pragma: no-cache" request, ATS is indeed copying it over into X-ATS-1, along with just setting X-ATS-2. So far so good.

 > GET /test.html HTTP/1.1
> User-Agent: curl/7.30.0
> Accept: */*
> Pragma: no-cache
> Host: example.com
>
< HTTP/1.1 200 OK
< Date: Fri, 22 Nov 2013 18:42:13 GMT
< Content-Type: text/html
< Content-Length: 2
< Connection: keep-alive
< Server: Apache/2
< X-From-Apache: Hi from apache
< Last-Modified: Fri, 22 Nov 2013 18:41:52 GMT
< ETag: "2-4ebc85e219631"
< Accept-Ranges: bytes
< Cache-Control: max-age=3600
< Expires: Fri, 22 Nov 2013 19:42:13 GMT
< Vary: Accept-Encoding
< Age: 0
< X-ATS-1: Hi from apache
< X-ATS-2: Hi


For the conditional request though, ATS added that one explicit header but didn't copy over X-From-Apache:

> GET /test.html HTTP/1.1
> User-Agent: curl/7.30.0
> Accept: */*
> If-Modified-Since: Fri, 22 Nov 2013 18:41:52 GMT
> Host: example.com
>
< HTTP/1.1 304 Not Modified
< Date: Fri, 22 Nov 2013 18:42:36 GMT
< Connection: keep-alive
< Etag: "2-4ebc85e219631"
< Expires: Fri, 22 Nov 2013 19:42:13 GMT
< Cache-Control: max-age=3600
< Vary: Accept-Encoding
< X-ATS-2: Hi


If I send a non-conditional request (but without the Pragma: no-cache like in the first example), I get X-ATS-1 like in the Pragma: no-cache example. So 200 responses, whether cached or not cached, are getting the header copied over by headers_rewrite, just not in 304's.

Is the not copying headers for a 304 expected behavior or should I open a ticket about it?

Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
On Fri, Nov 22, 2013 at 11:25 AM, Shu Kit Chan <[hidden email]> wrote:
I think in your "conditional request" example, the response does not have a X-From-Apache header.
The code is done in such a way that it will ignore add-header if the value is empty.



If I send a non-conditional request (but without the Pragma: no-cache like in the first example), I get X-ATS-1 like in the Pragma: no-cache example. So 200 responses, whether cached or not cached, are getting the header copied over by headers_rewrite, just not in 304's.

Is the not copying headers for a 304 expected behavior or should I open a ticket about it?


Not sure what you mean. There's no corresponding origin request for the conditional request, since it was successfully cached. The 304 is coming straight out of ATS and not re-requesting from the origin server. So presumably ATS is filtering the list of headers it makes available for the headers_rewrite module.


From what I can tell, the HttpTransact::build_response function in proxy/http/HttpTransact.cc seems to be doing that filtering.

If doing this via headers_rewrite turns out not to be an option, it *seems* like I could add a corresponding MIME_FIELD_*, MIME_LEN_*, and MIME_PRESENCE_* entry to the arrays there (in 4.1.1, lines starting with 7697), as well as adding:

* A new entry in proxy/hdrs/MIME.cc as well as the spots where things are assigned: MIME_LEN_* = hdrtoken_wks_to_length(MIME_FIELD_*);

* A new entry to the fields array in lib/ts/mkdfa.c : {"MyHeader", "MIME_FIELD_...", 0},

* Find a new slot in the 'tokenized string mime presence masks' define's for MIME_PRESENCE_* in proxy/hdrs/HdrToken.h


Though I'd obviously love to be able to do this without mucking with source code, since the likelihood of me causing random segfaults is high.
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Shu Kit Chan
From the header_rewrite plugin perspective, 
the 304 is coming straight out of ATS and not from origin server. That's fine.
So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
But the add-header operation for "X-ATS-2" is still getting done without problem.

Thanks.

Kit


On Fri, Nov 22, 2013 at 4:20 PM, Mark Moseley <[hidden email]> wrote:
On Fri, Nov 22, 2013 at 11:25 AM, Shu Kit Chan <[hidden email]> wrote:
I think in your "conditional request" example, the response does not have a X-From-Apache header.
The code is done in such a way that it will ignore add-header if the value is empty.



If I send a non-conditional request (but without the Pragma: no-cache like in the first example), I get X-ATS-1 like in the Pragma: no-cache example. So 200 responses, whether cached or not cached, are getting the header copied over by headers_rewrite, just not in 304's.

Is the not copying headers for a 304 expected behavior or should I open a ticket about it?


Not sure what you mean. There's no corresponding origin request for the conditional request, since it was successfully cached. The 304 is coming straight out of ATS and not re-requesting from the origin server. So presumably ATS is filtering the list of headers it makes available for the headers_rewrite module.


From what I can tell, the HttpTransact::build_response function in proxy/http/HttpTransact.cc seems to be doing that filtering.

If doing this via headers_rewrite turns out not to be an option, it *seems* like I could add a corresponding MIME_FIELD_*, MIME_LEN_*, and MIME_PRESENCE_* entry to the arrays there (in 4.1.1, lines starting with 7697), as well as adding:

* A new entry in proxy/hdrs/MIME.cc as well as the spots where things are assigned: MIME_LEN_* = hdrtoken_wks_to_length(MIME_FIELD_*);

* A new entry to the fields array in lib/ts/mkdfa.c : {"MyHeader", "MIME_FIELD_...", 0},

* Find a new slot in the 'tokenized string mime presence masks' define's for MIME_PRESENCE_* in proxy/hdrs/HdrToken.h


Though I'd obviously love to be able to do this without mucking with source code, since the likelihood of me causing random segfaults is high.

Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
On Fri, Nov 22, 2013 at 4:46 PM, Shu Kit Chan <[hidden email]> wrote:
From the header_rewrite plugin perspective, 
the 304 is coming straight out of ATS and not from origin server. That's fine.
So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
But the add-header operation for "X-ATS-2" is still getting done without problem.



However the header that's not seen by the headers_rewrite module is stored in the cached response. If I do a non-conditional, non-"Pragma: no-cache" request, there's likewise no request to the origin server but the header gets seen by the headers_module.

So I'm trying to figure out how to amend the list of headers ATS should send back, in the event of a cache-fulfilled 304 request.
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Shu Kit Chan
In reply to this post by Shu Kit Chan
After re-reading your message, can you see if the results are any different if you use READ_RESPONSE_HDR_HOOK instead of SEND_RESPONSE_HDR_HOOK ?

Thanks.

Kit


On Fri, Nov 22, 2013 at 4:46 PM, Shu Kit Chan <[hidden email]> wrote:
From the header_rewrite plugin perspective, 
the 304 is coming straight out of ATS and not from origin server. That's fine.
So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
But the add-header operation for "X-ATS-2" is still getting done without problem.

Thanks.

Kit


On Fri, Nov 22, 2013 at 4:20 PM, Mark Moseley <[hidden email]> wrote:
On Fri, Nov 22, 2013 at 11:25 AM, Shu Kit Chan <[hidden email]> wrote:
I think in your "conditional request" example, the response does not have a X-From-Apache header.
The code is done in such a way that it will ignore add-header if the value is empty.



If I send a non-conditional request (but without the Pragma: no-cache like in the first example), I get X-ATS-1 like in the Pragma: no-cache example. So 200 responses, whether cached or not cached, are getting the header copied over by headers_rewrite, just not in 304's.

Is the not copying headers for a 304 expected behavior or should I open a ticket about it?


Not sure what you mean. There's no corresponding origin request for the conditional request, since it was successfully cached. The 304 is coming straight out of ATS and not re-requesting from the origin server. So presumably ATS is filtering the list of headers it makes available for the headers_rewrite module.


From what I can tell, the HttpTransact::build_response function in proxy/http/HttpTransact.cc seems to be doing that filtering.

If doing this via headers_rewrite turns out not to be an option, it *seems* like I could add a corresponding MIME_FIELD_*, MIME_LEN_*, and MIME_PRESENCE_* entry to the arrays there (in 4.1.1, lines starting with 7697), as well as adding:

* A new entry in proxy/hdrs/MIME.cc as well as the spots where things are assigned: MIME_LEN_* = hdrtoken_wks_to_length(MIME_FIELD_*);

* A new entry to the fields array in lib/ts/mkdfa.c : {"MyHeader", "MIME_FIELD_...", 0},

* Find a new slot in the 'tokenized string mime presence masks' define's for MIME_PRESENCE_* in proxy/hdrs/HdrToken.h


Though I'd obviously love to be able to do this without mucking with source code, since the likelihood of me causing random segfaults is high.


Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
On Fri, Nov 22, 2013 at 5:00 PM, Shu Kit Chan <[hidden email]> wrote:
After re-reading your message, can you see if the results are any different if you use READ_RESPONSE_HDR_HOOK instead of SEND_RESPONSE_HDR_HOOK ?

Thanks.

Kit


With SEND_RESPONSE_HDR_HOOK, I don't get either of the headers set by headers_rewrite module in a 304 response.

Nor do I get the header being copied from X-From-Apache.
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Shu Kit Chan
Thanks for trying it out. I think header_rewrite plugin cannot help you in this particular case.

Kit


On Fri, Nov 22, 2013 at 5:06 PM, Mark Moseley <[hidden email]> wrote:
On Fri, Nov 22, 2013 at 5:00 PM, Shu Kit Chan <[hidden email]> wrote:
After re-reading your message, can you see if the results are any different if you use READ_RESPONSE_HDR_HOOK instead of SEND_RESPONSE_HDR_HOOK ?

Thanks.

Kit


With SEND_RESPONSE_HDR_HOOK, I don't get either of the headers set by headers_rewrite module in a 304 response.

Nor do I get the header being copied from X-From-Apache.

Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

James Peach
In reply to this post by Mark Moseley
On Nov 22, 2013, at 4:59 PM, Mark Moseley <[hidden email]> wrote:

> On Fri, Nov 22, 2013 at 4:46 PM, Shu Kit Chan <[hidden email]> wrote:
> From the header_rewrite plugin perspective,
> the 304 is coming straight out of ATS and not from origin server. That's fine.
> So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
> But the add-header operation for "X-ATS-2" is still getting done without problem.
>
>
>
> However the header that's not seen by the headers_rewrite module is stored in the cached response. If I do a non-conditional, non-"Pragma: no-cache" request, there's likewise no request to the origin server but the header gets seen by the headers_module.
>
> So I'm trying to figure out how to amend the list of headers ATS should send back, in the event of a cache-fulfilled 304 request.

It might help to trace the "header_rewrite" diagnostic tag with proxy.config.diags.debug.tags. Can you also post your header_rewrite config file ... I've found that the syntax can be unintuitive ...

J
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
On Fri, Nov 22, 2013 at 6:14 PM, James Peach <[hidden email]> wrote:
On Nov 22, 2013, at 4:59 PM, Mark Moseley <[hidden email]> wrote:

> On Fri, Nov 22, 2013 at 4:46 PM, Shu Kit Chan <[hidden email]> wrote:
> From the header_rewrite plugin perspective,
> the 304 is coming straight out of ATS and not from origin server. That's fine.
> So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
> But the add-header operation for "X-ATS-2" is still getting done without problem.
>
>
>
> However the header that's not seen by the headers_rewrite module is stored in the cached response. If I do a non-conditional, non-"Pragma: no-cache" request, there's likewise no request to the origin server but the header gets seen by the headers_module.
>
> So I'm trying to figure out how to amend the list of headers ATS should send back, in the event of a cache-fulfilled 304 request.

It might help to trace the "header_rewrite" diagnostic tag with proxy.config.diags.debug.tags. Can you also post your header_rewrite config file ... I've found that the syntax can be unintuitive ..


The header_rewrite config:

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-1 %{HEADER:X-From-Apache}

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-2 Hi



Trace output:

This is after the initial "Pragma: no-cache" request:

[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) number of arguments: 2
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Loading header_rewrite config from /etc/trafficserver/header_rewrite.config
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 1: cond %{SEND_RESPONSE_HDR_HOOK}
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 2: add-header X-ATS-1 %{HEADER:X-From-Apache}
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Operator
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorHeaders
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Value
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorAddHeader
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding operator: add-header(X-ATS-1)
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Condition
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for ConditionHeader, client 0
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Matcher
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 3:
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 4: cond %{SEND_RESPONSE_HDR_HOOK}
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding rule to hook=5
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 5: add-header X-ATS-2 Hi
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Operator
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorHeaders
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Value
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorAddHeader
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding operator: add-header(X-ATS-2)
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 6:
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding rule to hook=5
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) adding hook: 5


Then this is the If-Modified-Since request for the same header (satisfied out of the cache, no origin request)

[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Resources (InkAPI)
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Building resource structure for hook (5)
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client request header buffers
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client response header buffers
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Getting Header: X-From-Apache, field_loc: 0x4fc6fa0
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Appending HEADER(X-From-Apache) to evaluation value -> Hi from apache
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-1: Hi from apache
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-1
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-2: Hi
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-2
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Resources (InkAPI)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Building resource structure for hook (5)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client request header buffers
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client response header buffers
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Getting Header: X-From-Apache, field_loc: (nil)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Would set header X-ATS-1 to an empty value, skipping
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-2: Hi
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-2
Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Shu Kit Chan
I think the problem is not with the plugin. The debug log is telling us that, i think. 
We can add a static header to the 304 response with no problem.

The situation is that - 

1) There is a custom header (X-From-Apache) in the original response from origin server.
2) This response is cached in ATS
3) When client uses IMS in the request, ATS responds with a 304. 
4) The custom header is nowhere to be found in the 304 respond
5) And thus the header_rewrite plugin cannot get its value.

I think ATS is doing the right thing for 304 as mentioned here - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
So how do we override this behavior and/or let the header_rewrite plugin to know about the X-From-Apache header in the original response? 

Thanks.

Kit


On Fri, Nov 22, 2013 at 6:36 PM, Mark Moseley <[hidden email]> wrote:
On Fri, Nov 22, 2013 at 6:14 PM, James Peach <[hidden email]> wrote:
On Nov 22, 2013, at 4:59 PM, Mark Moseley <[hidden email]> wrote:

> On Fri, Nov 22, 2013 at 4:46 PM, Shu Kit Chan <[hidden email]> wrote:
> From the header_rewrite plugin perspective,
> the 304 is coming straight out of ATS and not from origin server. That's fine.
> So all the plugin does is to look up "X-From-Apache" from this particular HTTP response between ATS and the client. It can't find it. So it cancelled the add-header operation for "X-ATS-1".
> But the add-header operation for "X-ATS-2" is still getting done without problem.
>
>
>
> However the header that's not seen by the headers_rewrite module is stored in the cached response. If I do a non-conditional, non-"Pragma: no-cache" request, there's likewise no request to the origin server but the header gets seen by the headers_module.
>
> So I'm trying to figure out how to amend the list of headers ATS should send back, in the event of a cache-fulfilled 304 request.

It might help to trace the "header_rewrite" diagnostic tag with proxy.config.diags.debug.tags. Can you also post your header_rewrite config file ... I've found that the syntax can be unintuitive ..


The header_rewrite config:


cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-1 %{HEADER:X-From-Apache}

cond %{SEND_RESPONSE_HDR_HOOK}
add-header X-ATS-2 Hi



Trace output:

This is after the initial "Pragma: no-cache" request:

[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) number of arguments: 2
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Loading header_rewrite config from /etc/trafficserver/header_rewrite.config
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 1: cond %{SEND_RESPONSE_HDR_HOOK}
[Nov 22 21:32:51.548] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 2: add-header X-ATS-1 %{HEADER:X-From-Apache}
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Operator
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorHeaders
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Value
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorAddHeader
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding operator: add-header(X-ATS-1)
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Condition
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for ConditionHeader, client 0
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Matcher
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 3:
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 4: cond %{SEND_RESPONSE_HDR_HOOK}
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding rule to hook=5
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 5: add-header X-ATS-2 Hi
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Parser
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Operator
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorHeaders
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Statement
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Value
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for OperatorAddHeader
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding operator: add-header(X-ATS-2)
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Reading line: 6:
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Adding rule to hook=5
[Nov 22 21:32:51.549] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) adding hook: 5


Then this is the If-Modified-Since request for the same header (satisfied out of the cache, no origin request)

[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Resources (InkAPI)
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Building resource structure for hook (5)
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client request header buffers
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client response header buffers
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Getting Header: X-From-Apache, field_loc: 0x4fc6fa0
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Appending HEADER(X-From-Apache) to evaluation value -> Hi from apache
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-1: Hi from apache
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-1
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-2: Hi
[Nov 22 21:32:56.772] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-2
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite_dbg) Calling CTOR for Resources (InkAPI)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Building resource structure for hook (5)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client request header buffers
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    Adding TXN client response header buffers
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Getting Header: X-From-Apache, field_loc: (nil)
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) Would set header X-ATS-1 to an empty value, skipping
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite) OperatorAddHeader::exec() invoked on header X-ATS-2: Hi
[Nov 22 21:33:04.412] Server {0x2ebb4ce3ddc0} DIAG: (header_rewrite)    adding header X-ATS-2

Reply | Threaded
Open this post in threaded view
|

Re: Adding headers to 304 Responses

Mark Moseley
On Fri, Nov 22, 2013 at 7:24 PM, Shu Kit Chan <[hidden email]> wrote:
I think the problem is not with the plugin. The debug log is telling us that, i think. 
We can add a static header to the 304 response with no problem.

The situation is that - 

1) There is a custom header (X-From-Apache) in the original response from origin server.
2) This response is cached in ATS
3) When client uses IMS in the request, ATS responds with a 304. 
4) The custom header is nowhere to be found in the 304 respond
5) And thus the header_rewrite plugin cannot get its value.

I think ATS is doing the right thing for 304 as mentioned here - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
So how do we override this behavior and/or let the header_rewrite plugin to know about the X-From-Apache header in the original response? 

Yeah, I don't mean to imply at any point that ATS is doing the wrong thing. I'm just trying to make it do something different :)

Your #1-5 sounds correct. Interestingly, for the 304s, the X-From-Apache header doesn't even get logged using the custom log %<{X-From-Apache}ssh> tag (though it does get logged successfully
for non-IMS requests just fine).

The background is that I'm working on fronting existing web servers with ATS. The existing Apache servers use the (real) headers I'm trying to add in their logging, so I'm trying to get those
same headers working with ATS so I can avoid overhauling the log processing that's already in place (it's a fairly big infrastructure, so it wouldn't be a trivial thing to do -- so non-trivial that I'd rather
modify the source code of ATS).

Everything else works great and I thought I was pretty much done, since I'd only ever tested non-conditional requests. But those have tripped me up a bit, so I'm looking for workarounds.