You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Hiroaki Nakamura <hn...@gmail.com> on 2016/05/13 02:12:20 UTC

Re: [Feature request] Add configs to ignore server Cache-Control: max-age and Expires

I tried and found that when I modify headers in TS_HTTP_READ_RESPONSE_HDR_HOOK,
the cached object has those modified headers, so when the next time a
request comes in,
the cached response with the modified headers is served.

This is not what I want. My requirement is to serve cached objects
with the original headers.
I think it cannot be done with a plugin.

So here I propose my request for modification again.

> How about adding a value to proxy.config.http.cache.required_headers?
> https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html#proxy-config-http-cache-required-headers
>
> 0 = no headers required to make document cacheable
> 1 = either the Last-Modified header, or an explicit lifetime header,
> Expires orCache-Control: max-age, is required
> 2 = explicit lifetime is required, Expires or Cache-Control: max-age
> 3 (new value) = explicit lifetime is required, Cache-Control: s-maxage
> (Expires or Cache-Control: max-age are ignored).

Please give me your feedbacks.

Regards,
Hiroaki

Re: [Feature request] Add configs to ignore server Cache-Control: max-age and Expires

Posted by Sudheer Vinukonda <su...@yahoo-inc.com.INVALID>.
In general, most (if not all) Header modifications are encouraged to be done using plugin API.
ts_lua or header_rewrite are a couple of such plugins that are bundled in the repo to provide certain type of Header operations amongst other things, but, there are instances where people still write their own custom plugins for specialized use cases that are not generic enough to be included in header_rewrite/ts_lua.
Having said that, if your use case is common enough and is not easily possible to implement using the API, it might also be possible to include in the core. 
It seems to me that your requirement is possible to implement using a custom plugin where you can handle duplicate headers etc, but, I'll let others chime in.
You may open a pull request on github with your patch and request for comments/review.
Thanks,
Sudheer 

    On Thursday, May 12, 2016 11:17 PM, Hiroaki Nakamura <hn...@gmail.com> wrote:
 

 Thanks for your comment.

The following is my understanding of what you said.

For example, I will ignore the max-age parameter and limit s-maxage to 60.
If the response from origin server contains the headers like:

< Cache-Control: s-maxage=180, max-age=360

Then I modify headers in READ_RESPONSE_HDR_HOOK like:

< Cache-Control: s-maxage=60
< X-Cache-Control: s-maxage=180, max-age=360

The original value of the second Cache-Control to X-Cache-Control
and the value of the second Cache-Control is modified to "s-maxage=60".

In SEND_RESPONSE_HDR_HOOK, modify headers back to the original headers.

Here is a simplified implementation for the proof of concept.
It has limitation that it cannot handle multiple Cache Control Headers

```
function read_response()
  ts.server_response.header['X-Cache-Control'] =
ts.server_response.header['Cache-Control']
  ts.server_response.header['Cache-Control'] = 's-maxage=60'
  return 0
end

function send_response()
  ts.client_response.header['Cache-Control'] =
ts.client_response.header['X-Cache-Control']
  ts.client_response.header['X-Cache-Control'] = nil
  return 0
end

function do_remap()
  ts.hook(TS_LUA_HOOK_READ_RESPONSE_HDR, read_response)
  ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
  return 0
end
```

However the renamed header name X-Cache-Control may collide with the original
headers. In my usecase, the origin servers are out of my control, so any header
names may be used.

And I think it is simpler to implement ignoring and limiting headers
in the Traffic Server
than modifying and restoring headers in a plugin.

After all, I think I will use my original modification as a private
patch to the Traffic Server.

Regards,
Hiroaki


2016-05-13 11:25 GMT+09:00 Sudheer Vinukonda <su...@yahoo-inc.com>:
> Hmm..it should be possible to do what you need with a plugin.
>
> For instance, going back to the solution you tried, perhaps you could
> instead of storing the CC headers in the Request context, rename them with
> custom names in the Response context (which should get cached) and rename
> them as required subsequently?
>
> "1. In TS_HTTP_READ_RESPONSE_HDR_HOOK, remove Expires and
> Cache-Control: max-age headers and keep the values in the request
> context.
> 2. In TS_HTTP_SEND_RESPONSE_HDR_HOOK, restore Expires and
> Cache-Control: max-age headers with the values stored in the request
> context."
>
>
>
> On Thursday, May 12, 2016, 7:14 PM, Hiroaki Nakamura <hn...@gmail.com>
> wrote:
>
> I tried and found that when I modify headers in
> TS_HTTP_READ_RESPONSE_HDR_HOOK,
> the cached object has those modified headers, so when the next time a
> request comes in,
> the cached response with the modified headers is served.
>
> This is not what I want. My requirement is to serve cached objects
> with the original headers.
> I think it cannot be done with a plugin.
>
> So here I propose my request for modification again.
>
>> How about adding a value to proxy.config.http.cache.required_headers?
>>
>> https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html#proxy-config-http-cache-required-headers
>>
>> 0 = no headers required to make document cacheable
>> 1 = either the Last-Modified header, or an explicit lifetime header,
>> Expires orCache-Control: max-age, is required
>> 2 = explicit lifetime is required, Expires or Cache-Control: max-age
>> 3 (new value) = explicit lifetime is required, Cache-Control: s-maxage
>> (Expires or Cache-Control: max-age are ignored).
>
> Please give me your feedbacks.
>
> Regards,
>
> Hiroaki


  

Re: [Feature request] Add configs to ignore server Cache-Control: max-age and Expires

Posted by Hiroaki Nakamura <hn...@gmail.com>.
Thanks for your comment.

The following is my understanding of what you said.

For example, I will ignore the max-age parameter and limit s-maxage to 60.
If the response from origin server contains the headers like:

< Cache-Control: s-maxage=180, max-age=360

Then I modify headers in READ_RESPONSE_HDR_HOOK like:

< Cache-Control: s-maxage=60
< X-Cache-Control: s-maxage=180, max-age=360

The original value of the second Cache-Control to X-Cache-Control
and the value of the second Cache-Control is modified to "s-maxage=60".

In SEND_RESPONSE_HDR_HOOK, modify headers back to the original headers.

Here is a simplified implementation for the proof of concept.
It has limitation that it cannot handle multiple Cache Control Headers

```
function read_response()
  ts.server_response.header['X-Cache-Control'] =
ts.server_response.header['Cache-Control']
  ts.server_response.header['Cache-Control'] = 's-maxage=60'
  return 0
end

function send_response()
  ts.client_response.header['Cache-Control'] =
ts.client_response.header['X-Cache-Control']
  ts.client_response.header['X-Cache-Control'] = nil
  return 0
end

function do_remap()
  ts.hook(TS_LUA_HOOK_READ_RESPONSE_HDR, read_response)
  ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
  return 0
end
```

However the renamed header name X-Cache-Control may collide with the original
headers. In my usecase, the origin servers are out of my control, so any header
names may be used.

And I think it is simpler to implement ignoring and limiting headers
in the Traffic Server
than modifying and restoring headers in a plugin.

After all, I think I will use my original modification as a private
patch to the Traffic Server.

Regards,
Hiroaki


2016-05-13 11:25 GMT+09:00 Sudheer Vinukonda <su...@yahoo-inc.com>:
> Hmm..it should be possible to do what you need with a plugin.
>
> For instance, going back to the solution you tried, perhaps you could
> instead of storing the CC headers in the Request context, rename them with
> custom names in the Response context (which should get cached) and rename
> them as required subsequently?
>
> "1. In TS_HTTP_READ_RESPONSE_HDR_HOOK, remove Expires and
> Cache-Control: max-age headers and keep the values in the request
> context.
> 2. In TS_HTTP_SEND_RESPONSE_HDR_HOOK, restore Expires and
> Cache-Control: max-age headers with the values stored in the request
> context."
>
>
>
> On Thursday, May 12, 2016, 7:14 PM, Hiroaki Nakamura <hn...@gmail.com>
> wrote:
>
> I tried and found that when I modify headers in
> TS_HTTP_READ_RESPONSE_HDR_HOOK,
> the cached object has those modified headers, so when the next time a
> request comes in,
> the cached response with the modified headers is served.
>
> This is not what I want. My requirement is to serve cached objects
> with the original headers.
> I think it cannot be done with a plugin.
>
> So here I propose my request for modification again.
>
>> How about adding a value to proxy.config.http.cache.required_headers?
>>
>> https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html#proxy-config-http-cache-required-headers
>>
>> 0 = no headers required to make document cacheable
>> 1 = either the Last-Modified header, or an explicit lifetime header,
>> Expires orCache-Control: max-age, is required
>> 2 = explicit lifetime is required, Expires or Cache-Control: max-age
>> 3 (new value) = explicit lifetime is required, Cache-Control: s-maxage
>> (Expires or Cache-Control: max-age are ignored).
>
> Please give me your feedbacks.
>
> Regards,
>
> Hiroaki

Re: [Feature request] Add configs to ignore server Cache-Control: max-age and Expires

Posted by Sudheer Vinukonda <su...@yahoo-inc.com.INVALID>.
 blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; } Hmm..it should be possible to do what you need with a plugin.
For instance, going back to the solution you tried, perhaps you could instead of storing the CC headers in the Request context, rename them with custom names in the Response context (which should get cached) and rename them as required subsequently? 
"1. In TS_HTTP_READ_RESPONSE_HDR_HOOK, remove Expires and
Cache-Control: max-age headers and keep the values in the request
context.
2. In TS_HTTP_SEND_RESPONSE_HDR_HOOK, restore Expires and
Cache-Control: max-age headers with the values stored in the request
context."




On Thursday, May 12, 2016, 7:14 PM, Hiroaki Nakamura <hn...@gmail.com> wrote:

I tried and found that when I modify headers in TS_HTTP_READ_RESPONSE_HDR_HOOK,
the cached object has those modified headers, so when the next time a
request comes in,
the cached response with the modified headers is served.

This is not what I want. My requirement is to serve cached objects
with the original headers.
I think it cannot be done with a plugin.

So here I propose my request for modification again.

> How about adding a value to proxy.config.http.cache.required_headers?
> https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html#proxy-config-http-cache-required-headers
>
> 0 = no headers required to make document cacheable
> 1 = either the Last-Modified header, or an explicit lifetime header,
> Expires orCache-Control: max-age, is required
> 2 = explicit lifetime is required, Expires or Cache-Control: max-age
> 3 (new value) = explicit lifetime is required, Cache-Control: s-maxage
> (Expires or Cache-Control: max-age are ignored).

Please give me your feedbacks.

Regards,
Hiroaki