You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by Benjamin Morel <be...@gmail.com> on 2017/12/11 16:57:00 UTC

Cache HIT/MISS header

*Sorry if this has been asked before, but I couldn't find it in the docs.*

I'm using ATS as a forward proxy. Is there a way to add a response header
to tell me if the request was a HIT or a MISS?

Something like: X-Cache: HIT

Thanks in advance,
Benjamin

Re: Cache HIT/MISS header

Posted by Veiko Kukk <ve...@gmail.com>.
2017-12-13 21:09 GMT+02:00 James Peach <jp...@apache.org>:

>
>
> I'd use the `xdebug` plugin, see <https://docs.trafficserver.
> apache.org/en/7.1.x/admin-guide/plugins/xdebug.en.html>. If you want the
> `X-Cache` header in every response, then you can use `header_rewrite` to
> inject the appropriate `X-Debug` header on every request.
>
>
Why would you rewrite headers twice and include unneccessary x-debug plugin
to achieve what can be done much simpler way. This does not seem optimal
way.

Veiko

Re: Cache HIT/MISS header

Posted by James Peach <jp...@apache.org>.

> On Dec 11, 2017, at 8:57 AM, Benjamin Morel <be...@gmail.com> wrote:
> 
> Sorry if this has been asked before, but I couldn't find it in the docs.
> 
> I'm using ATS as a forward proxy. Is there a way to add a response header to tell me if the request was a HIT or a MISS?
> 
> Something like: X-Cache: HIT

I'd use the `xdebug` plugin, see <https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/xdebug.en.html>. If you want the `X-Cache` header in every response, then you can use `header_rewrite` to inject the appropriate `X-Debug` header on every request.

J

Re: Cache HIT/MISS header

Posted by Veiko Kukk <ve...@gmail.com>.
Hi Benjamin,

I used the source as documentation
https://github.com/apache/trafficserver/blob/master/cmd/traffic_via/traffic_via.cc

Veiko


2017-12-13 19:33 GMT+02:00 Benjamin Morel <be...@gmail.com>:

> Thank you all for your replies. TBH I expected it to be much simpler!
>
> That being said, proxy.config.http.insert_request_via_str, and parsing
> the resulting Via header, looks like the way to go.
>
> Apart from the obscure decoder, is there a documentation for the format of
> the Via transaction codes?
> With a listing of all possible statuses (cR = fresh Ram hit, cH = fresh
> hit, ...)
>
> I couldn't find this in the doc.
>
> Thanks in advance,
> Ben
>
> On 13 December 2017 at 10:43, Veiko Kukk <ve...@gmail.com> wrote:
>
>> If you also need MISS (our setup does not, we know amount of requests and
>> amount of HIT's), you need to add another condition with set-header X-Cache
>> "MISS"
>>
>> --
>> Veiko
>>
>>
>> 2017-12-12 14:10 GMT+02:00 Veiko Kukk <ve...@gmail.com>:
>>
>>> Hi,
>>>
>>> I recently had exact same task: to include cache status in response
>>> headers. That's what I did:
>>>
>>> * proxy.config.http.insert_response_via_str 2
>>> * Using header_rewrite plugin to create additional header with following
>>> config:
>>> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
>>> cond %{HEADER:Via} /(\[cH|\[cR)/
>>> set-header X-Cache "HIT"
>>>
>>> Veiko
>>>
>>>
>>> 2017-12-12 2:29 GMT+02:00 Igor Cicimov <ig...@encompasscorporation.com>:
>>>
>>>> You can use the Via header:
>>>>
>>>> ############################################################
>>>> ##################
>>>> # Via: headers. Docs:
>>>> #     https://docs.trafficserver.apache.org/records.config#proxy-c
>>>> onfig-http-insert-response-via-str
>>>> ############################################################
>>>> ##################
>>>> CONFIG proxy.config.http.insert_request_via_str INT 1
>>>> CONFIG proxy.config.http.insert_response_via_str INT 3
>>>> CONFIG proxy.config.http.response_via_str STRING ATS
>>>>
>>>> that will insert values like below that you can decode:
>>>>
>>>> # traffic_via  '[cHs f ]'
>>>> Via header is [cHs f ], Length is 8
>>>> Via Header Details:
>>>> *Result of Traffic Server cache lookup for URL          :in cache,
>>>> fresh (a cache "HIT")*
>>>> Response information received from origin server       :no server
>>>> connection needed
>>>> Result of document write-to-cache:                     :no cache write
>>>> performed
>>>>
>>>> for detailed stats (insert_response_via_str INT 3):
>>>>
>>>> # traffic_via 'uScHs f p eN:t cCHi p s '
>>>> Via header is uScHs f p eN:t cCHi p s , Length is 24
>>>> Via Header Details:
>>>> Request headers received from client                   :simple request
>>>> (not conditional)
>>>> *Result of Traffic Server cache lookup for URL          :in cache,
>>>> fresh (a cache "HIT")*
>>>> Response information received from origin server       :no server
>>>> connection needed
>>>> Result of document write-to-cache:                     :no cache write
>>>> performed
>>>> Proxy operation result                                 :unknown
>>>> Error codes (if any)                                   :no error
>>>> Tunnel info                                            :no tunneling
>>>> Cache Type                                             :cache
>>>> *Cache Lookup Result                                    :cache hit*
>>>> ICP status                                             :no icp
>>>> Parent proxy connection status                         :no parent proxy
>>>> or unknown
>>>> Origin server connection status                        :no server
>>>> connection needed
>>>>
>>>> but you might be already familiar with it and not exactly what you need.
>>>>
>>>>
>>>> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org>
>>>> wrote:
>>>>
>>>>> Perhaps use the X-Debug header:
>>>>> https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/p
>>>>> lugins/xdebug.en.html
>>>>> and maybe a global header_rewrite rule to add the magic header to make
>>>>> the debug part appear?
>>>>>
>>>>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
>>>>> <be...@gmail.com> wrote:
>>>>> > Sorry if this has been asked before, but I couldn't find it in the
>>>>> docs.
>>>>> >
>>>>> > I'm using ATS as a forward proxy. Is there a way to add a response
>>>>> header to
>>>>> > tell me if the request was a HIT or a MISS?
>>>>> >
>>>>> > Something like: X-Cache: HIT
>>>>> >
>>>>> > Thanks in advance,
>>>>> > Benjamin
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>

Re: Cache HIT/MISS header

Posted by Benjamin Morel <be...@gmail.com>.
> I used the source as documentation https://github.
> com/apache/trafficserver/blob/master/cmd/traffic_via/traffic_via.cc


https://docs.trafficserver.apache.org/en/7.1.x/
> appendices/faq.en.html#how-do-i-interpret-the-via-header-code


Thanks to both of you!

Ben

On 14 December 2017 at 17:35, Miles Libbey <ml...@apache.org> wrote:

> On Wed, Dec 13, 2017 at 9:33 AM, Benjamin Morel
> <be...@gmail.com> wrote:
> > Thank you all for your replies. TBH I expected it to be much simpler!
> >
> > That being said, proxy.config.http.insert_request_via_str, and parsing
> the
> > resulting Via header, looks like the way to go.
> >
> > Apart from the obscure decoder, is there a documentation for the format
> of
> > the Via transaction codes?
>
> https://docs.trafficserver.apache.org/en/7.1.x/
> appendices/faq.en.html#how-do-i-interpret-the-via-header-code
>
> > With a listing of all possible statuses (cR = fresh Ram hit, cH = fresh
> hit,
> > ...)
> >
> > I couldn't find this in the doc.
> >
> > Thanks in advance,
> > Ben
> >
> > On 13 December 2017 at 10:43, Veiko Kukk <ve...@gmail.com> wrote:
> >>
> >> If you also need MISS (our setup does not, we know amount of requests
> and
> >> amount of HIT's), you need to add another condition with set-header
> X-Cache
> >> "MISS"
> >>
> >> --
> >> Veiko
> >>
> >>
> >> 2017-12-12 14:10 GMT+02:00 Veiko Kukk <ve...@gmail.com>:
> >>>
> >>> Hi,
> >>>
> >>> I recently had exact same task: to include cache status in response
> >>> headers. That's what I did:
> >>>
> >>> * proxy.config.http.insert_response_via_str 2
> >>> * Using header_rewrite plugin to create additional header with
> following
> >>> config:
> >>> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
> >>> cond %{HEADER:Via} /(\[cH|\[cR)/
> >>> set-header X-Cache "HIT"
> >>>
> >>> Veiko
> >>>
> >>>
> >>> 2017-12-12 2:29 GMT+02:00 Igor Cicimov <igorc@encompasscorporation.com
> >:
> >>>>
> >>>> You can use the Via header:
> >>>>
> >>>>
> >>>> ############################################################
> ##################
> >>>> # Via: headers. Docs:
> >>>> #
> >>>> https://docs.trafficserver.apache.org/records.config#
> proxy-config-http-insert-response-via-str
> >>>>
> >>>> ############################################################
> ##################
> >>>> CONFIG proxy.config.http.insert_request_via_str INT 1
> >>>> CONFIG proxy.config.http.insert_response_via_str INT 3
> >>>> CONFIG proxy.config.http.response_via_str STRING ATS
> >>>>
> >>>> that will insert values like below that you can decode:
> >>>>
> >>>> # traffic_via  '[cHs f ]'
> >>>> Via header is [cHs f ], Length is 8
> >>>> Via Header Details:
> >>>> Result of Traffic Server cache lookup for URL          :in cache,
> fresh
> >>>> (a cache "HIT")
> >>>> Response information received from origin server       :no server
> >>>> connection needed
> >>>> Result of document write-to-cache:                     :no cache write
> >>>> performed
> >>>>
> >>>> for detailed stats (insert_response_via_str INT 3):
> >>>>
> >>>> # traffic_via 'uScHs f p eN:t cCHi p s '
> >>>> Via header is uScHs f p eN:t cCHi p s , Length is 24
> >>>> Via Header Details:
> >>>> Request headers received from client                   :simple request
> >>>> (not conditional)
> >>>> Result of Traffic Server cache lookup for URL          :in cache,
> fresh
> >>>> (a cache "HIT")
> >>>> Response information received from origin server       :no server
> >>>> connection needed
> >>>> Result of document write-to-cache:                     :no cache write
> >>>> performed
> >>>> Proxy operation result                                 :unknown
> >>>> Error codes (if any)                                   :no error
> >>>> Tunnel info                                            :no tunneling
> >>>> Cache Type                                             :cache
> >>>> Cache Lookup Result                                    :cache hit
> >>>> ICP status                                             :no icp
> >>>> Parent proxy connection status                         :no parent
> proxy
> >>>> or unknown
> >>>> Origin server connection status                        :no server
> >>>> connection needed
> >>>>
> >>>> but you might be already familiar with it and not exactly what you
> need.
> >>>>
> >>>>
> >>>> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org>
> >>>> wrote:
> >>>>>
> >>>>> Perhaps use the X-Debug header:
> >>>>>
> >>>>> https://docs.trafficserver.apache.org/en/7.1.x/admin-
> guide/plugins/xdebug.en.html
> >>>>> and maybe a global header_rewrite rule to add the magic header to
> make
> >>>>> the debug part appear?
> >>>>>
> >>>>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
> >>>>> <be...@gmail.com> wrote:
> >>>>> > Sorry if this has been asked before, but I couldn't find it in the
> >>>>> > docs.
> >>>>> >
> >>>>> > I'm using ATS as a forward proxy. Is there a way to add a response
> >>>>> > header to
> >>>>> > tell me if the request was a HIT or a MISS?
> >>>>> >
> >>>>> > Something like: X-Cache: HIT
> >>>>> >
> >>>>> > Thanks in advance,
> >>>>> > Benjamin
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >
>

Re: Cache HIT/MISS header

Posted by Miles Libbey <ml...@apache.org>.
On Wed, Dec 13, 2017 at 9:33 AM, Benjamin Morel
<be...@gmail.com> wrote:
> Thank you all for your replies. TBH I expected it to be much simpler!
>
> That being said, proxy.config.http.insert_request_via_str, and parsing the
> resulting Via header, looks like the way to go.
>
> Apart from the obscure decoder, is there a documentation for the format of
> the Via transaction codes?

https://docs.trafficserver.apache.org/en/7.1.x/appendices/faq.en.html#how-do-i-interpret-the-via-header-code

> With a listing of all possible statuses (cR = fresh Ram hit, cH = fresh hit,
> ...)
>
> I couldn't find this in the doc.
>
> Thanks in advance,
> Ben
>
> On 13 December 2017 at 10:43, Veiko Kukk <ve...@gmail.com> wrote:
>>
>> If you also need MISS (our setup does not, we know amount of requests and
>> amount of HIT's), you need to add another condition with set-header X-Cache
>> "MISS"
>>
>> --
>> Veiko
>>
>>
>> 2017-12-12 14:10 GMT+02:00 Veiko Kukk <ve...@gmail.com>:
>>>
>>> Hi,
>>>
>>> I recently had exact same task: to include cache status in response
>>> headers. That's what I did:
>>>
>>> * proxy.config.http.insert_response_via_str 2
>>> * Using header_rewrite plugin to create additional header with following
>>> config:
>>> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
>>> cond %{HEADER:Via} /(\[cH|\[cR)/
>>> set-header X-Cache "HIT"
>>>
>>> Veiko
>>>
>>>
>>> 2017-12-12 2:29 GMT+02:00 Igor Cicimov <ig...@encompasscorporation.com>:
>>>>
>>>> You can use the Via header:
>>>>
>>>>
>>>> ##############################################################################
>>>> # Via: headers. Docs:
>>>> #
>>>> https://docs.trafficserver.apache.org/records.config#proxy-config-http-insert-response-via-str
>>>>
>>>> ##############################################################################
>>>> CONFIG proxy.config.http.insert_request_via_str INT 1
>>>> CONFIG proxy.config.http.insert_response_via_str INT 3
>>>> CONFIG proxy.config.http.response_via_str STRING ATS
>>>>
>>>> that will insert values like below that you can decode:
>>>>
>>>> # traffic_via  '[cHs f ]'
>>>> Via header is [cHs f ], Length is 8
>>>> Via Header Details:
>>>> Result of Traffic Server cache lookup for URL          :in cache, fresh
>>>> (a cache "HIT")
>>>> Response information received from origin server       :no server
>>>> connection needed
>>>> Result of document write-to-cache:                     :no cache write
>>>> performed
>>>>
>>>> for detailed stats (insert_response_via_str INT 3):
>>>>
>>>> # traffic_via 'uScHs f p eN:t cCHi p s '
>>>> Via header is uScHs f p eN:t cCHi p s , Length is 24
>>>> Via Header Details:
>>>> Request headers received from client                   :simple request
>>>> (not conditional)
>>>> Result of Traffic Server cache lookup for URL          :in cache, fresh
>>>> (a cache "HIT")
>>>> Response information received from origin server       :no server
>>>> connection needed
>>>> Result of document write-to-cache:                     :no cache write
>>>> performed
>>>> Proxy operation result                                 :unknown
>>>> Error codes (if any)                                   :no error
>>>> Tunnel info                                            :no tunneling
>>>> Cache Type                                             :cache
>>>> Cache Lookup Result                                    :cache hit
>>>> ICP status                                             :no icp
>>>> Parent proxy connection status                         :no parent proxy
>>>> or unknown
>>>> Origin server connection status                        :no server
>>>> connection needed
>>>>
>>>> but you might be already familiar with it and not exactly what you need.
>>>>
>>>>
>>>> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org>
>>>> wrote:
>>>>>
>>>>> Perhaps use the X-Debug header:
>>>>>
>>>>> https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/xdebug.en.html
>>>>> and maybe a global header_rewrite rule to add the magic header to make
>>>>> the debug part appear?
>>>>>
>>>>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
>>>>> <be...@gmail.com> wrote:
>>>>> > Sorry if this has been asked before, but I couldn't find it in the
>>>>> > docs.
>>>>> >
>>>>> > I'm using ATS as a forward proxy. Is there a way to add a response
>>>>> > header to
>>>>> > tell me if the request was a HIT or a MISS?
>>>>> >
>>>>> > Something like: X-Cache: HIT
>>>>> >
>>>>> > Thanks in advance,
>>>>> > Benjamin
>>>>
>>>>
>>>>
>>>
>>
>

Re: Cache HIT/MISS header

Posted by Benjamin Morel <be...@gmail.com>.
Thank you all for your replies. TBH I expected it to be much simpler!

That being said, proxy.config.http.insert_request_via_str, and parsing the
resulting Via header, looks like the way to go.

Apart from the obscure decoder, is there a documentation for the format of
the Via transaction codes?
With a listing of all possible statuses (cR = fresh Ram hit, cH = fresh
hit, ...)

I couldn't find this in the doc.

Thanks in advance,
Ben

On 13 December 2017 at 10:43, Veiko Kukk <ve...@gmail.com> wrote:

> If you also need MISS (our setup does not, we know amount of requests and
> amount of HIT's), you need to add another condition with set-header X-Cache
> "MISS"
>
> --
> Veiko
>
>
> 2017-12-12 14:10 GMT+02:00 Veiko Kukk <ve...@gmail.com>:
>
>> Hi,
>>
>> I recently had exact same task: to include cache status in response
>> headers. That's what I did:
>>
>> * proxy.config.http.insert_response_via_str 2
>> * Using header_rewrite plugin to create additional header with following
>> config:
>> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
>> cond %{HEADER:Via} /(\[cH|\[cR)/
>> set-header X-Cache "HIT"
>>
>> Veiko
>>
>>
>> 2017-12-12 2:29 GMT+02:00 Igor Cicimov <ig...@encompasscorporation.com>:
>>
>>> You can use the Via header:
>>>
>>> ############################################################
>>> ##################
>>> # Via: headers. Docs:
>>> #     https://docs.trafficserver.apache.org/records.config#proxy-c
>>> onfig-http-insert-response-via-str
>>> ############################################################
>>> ##################
>>> CONFIG proxy.config.http.insert_request_via_str INT 1
>>> CONFIG proxy.config.http.insert_response_via_str INT 3
>>> CONFIG proxy.config.http.response_via_str STRING ATS
>>>
>>> that will insert values like below that you can decode:
>>>
>>> # traffic_via  '[cHs f ]'
>>> Via header is [cHs f ], Length is 8
>>> Via Header Details:
>>> *Result of Traffic Server cache lookup for URL          :in cache, fresh
>>> (a cache "HIT")*
>>> Response information received from origin server       :no server
>>> connection needed
>>> Result of document write-to-cache:                     :no cache write
>>> performed
>>>
>>> for detailed stats (insert_response_via_str INT 3):
>>>
>>> # traffic_via 'uScHs f p eN:t cCHi p s '
>>> Via header is uScHs f p eN:t cCHi p s , Length is 24
>>> Via Header Details:
>>> Request headers received from client                   :simple request
>>> (not conditional)
>>> *Result of Traffic Server cache lookup for URL          :in cache, fresh
>>> (a cache "HIT")*
>>> Response information received from origin server       :no server
>>> connection needed
>>> Result of document write-to-cache:                     :no cache write
>>> performed
>>> Proxy operation result                                 :unknown
>>> Error codes (if any)                                   :no error
>>> Tunnel info                                            :no tunneling
>>> Cache Type                                             :cache
>>> *Cache Lookup Result                                    :cache hit*
>>> ICP status                                             :no icp
>>> Parent proxy connection status                         :no parent proxy
>>> or unknown
>>> Origin server connection status                        :no server
>>> connection needed
>>>
>>> but you might be already familiar with it and not exactly what you need.
>>>
>>>
>>> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org>
>>> wrote:
>>>
>>>> Perhaps use the X-Debug header:
>>>> https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/p
>>>> lugins/xdebug.en.html
>>>> and maybe a global header_rewrite rule to add the magic header to make
>>>> the debug part appear?
>>>>
>>>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
>>>> <be...@gmail.com> wrote:
>>>> > Sorry if this has been asked before, but I couldn't find it in the
>>>> docs.
>>>> >
>>>> > I'm using ATS as a forward proxy. Is there a way to add a response
>>>> header to
>>>> > tell me if the request was a HIT or a MISS?
>>>> >
>>>> > Something like: X-Cache: HIT
>>>> >
>>>> > Thanks in advance,
>>>> > Benjamin
>>>>
>>>
>>>
>>>
>>
>

Re: Cache HIT/MISS header

Posted by Veiko Kukk <ve...@gmail.com>.
If you also need MISS (our setup does not, we know amount of requests and
amount of HIT's), you need to add another condition with set-header X-Cache
"MISS"

-- 
Veiko


2017-12-12 14:10 GMT+02:00 Veiko Kukk <ve...@gmail.com>:

> Hi,
>
> I recently had exact same task: to include cache status in response
> headers. That's what I did:
>
> * proxy.config.http.insert_response_via_str 2
> * Using header_rewrite plugin to create additional header with following
> config:
> cond %{SEND_RESPONSE_HDR_HOOK} [AND]
> cond %{HEADER:Via} /(\[cH|\[cR)/
> set-header X-Cache "HIT"
>
> Veiko
>
>
> 2017-12-12 2:29 GMT+02:00 Igor Cicimov <ig...@encompasscorporation.com>:
>
>> You can use the Via header:
>>
>> ############################################################
>> ##################
>> # Via: headers. Docs:
>> #     https://docs.trafficserver.apache.org/records.config#proxy-
>> config-http-insert-response-via-str
>> ############################################################
>> ##################
>> CONFIG proxy.config.http.insert_request_via_str INT 1
>> CONFIG proxy.config.http.insert_response_via_str INT 3
>> CONFIG proxy.config.http.response_via_str STRING ATS
>>
>> that will insert values like below that you can decode:
>>
>> # traffic_via  '[cHs f ]'
>> Via header is [cHs f ], Length is 8
>> Via Header Details:
>> *Result of Traffic Server cache lookup for URL          :in cache, fresh
>> (a cache "HIT")*
>> Response information received from origin server       :no server
>> connection needed
>> Result of document write-to-cache:                     :no cache write
>> performed
>>
>> for detailed stats (insert_response_via_str INT 3):
>>
>> # traffic_via 'uScHs f p eN:t cCHi p s '
>> Via header is uScHs f p eN:t cCHi p s , Length is 24
>> Via Header Details:
>> Request headers received from client                   :simple request
>> (not conditional)
>> *Result of Traffic Server cache lookup for URL          :in cache, fresh
>> (a cache "HIT")*
>> Response information received from origin server       :no server
>> connection needed
>> Result of document write-to-cache:                     :no cache write
>> performed
>> Proxy operation result                                 :unknown
>> Error codes (if any)                                   :no error
>> Tunnel info                                            :no tunneling
>> Cache Type                                             :cache
>> *Cache Lookup Result                                    :cache hit*
>> ICP status                                             :no icp
>> Parent proxy connection status                         :no parent proxy
>> or unknown
>> Origin server connection status                        :no server
>> connection needed
>>
>> but you might be already familiar with it and not exactly what you need.
>>
>>
>> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org>
>> wrote:
>>
>>> Perhaps use the X-Debug header:
>>> https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/p
>>> lugins/xdebug.en.html
>>> and maybe a global header_rewrite rule to add the magic header to make
>>> the debug part appear?
>>>
>>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
>>> <be...@gmail.com> wrote:
>>> > Sorry if this has been asked before, but I couldn't find it in the
>>> docs.
>>> >
>>> > I'm using ATS as a forward proxy. Is there a way to add a response
>>> header to
>>> > tell me if the request was a HIT or a MISS?
>>> >
>>> > Something like: X-Cache: HIT
>>> >
>>> > Thanks in advance,
>>> > Benjamin
>>>
>>
>>
>>
>

Re: Cache HIT/MISS header

Posted by Veiko Kukk <ve...@gmail.com>.
Hi,

I recently had exact same task: to include cache status in response
headers. That's what I did:

* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with following
config:
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"

Veiko


2017-12-12 2:29 GMT+02:00 Igor Cicimov <ig...@encompasscorporation.com>:

> You can use the Via header:
>
> ############################################################
> ##################
> # Via: headers. Docs:
> #     https://docs.trafficserver.apache.org/records.config#
> proxy-config-http-insert-response-via-str
> ############################################################
> ##################
> CONFIG proxy.config.http.insert_request_via_str INT 1
> CONFIG proxy.config.http.insert_response_via_str INT 3
> CONFIG proxy.config.http.response_via_str STRING ATS
>
> that will insert values like below that you can decode:
>
> # traffic_via  '[cHs f ]'
> Via header is [cHs f ], Length is 8
> Via Header Details:
> *Result of Traffic Server cache lookup for URL          :in cache, fresh
> (a cache "HIT")*
> Response information received from origin server       :no server
> connection needed
> Result of document write-to-cache:                     :no cache write
> performed
>
> for detailed stats (insert_response_via_str INT 3):
>
> # traffic_via 'uScHs f p eN:t cCHi p s '
> Via header is uScHs f p eN:t cCHi p s , Length is 24
> Via Header Details:
> Request headers received from client                   :simple request
> (not conditional)
> *Result of Traffic Server cache lookup for URL          :in cache, fresh
> (a cache "HIT")*
> Response information received from origin server       :no server
> connection needed
> Result of document write-to-cache:                     :no cache write
> performed
> Proxy operation result                                 :unknown
> Error codes (if any)                                   :no error
> Tunnel info                                            :no tunneling
> Cache Type                                             :cache
> *Cache Lookup Result                                    :cache hit*
> ICP status                                             :no icp
> Parent proxy connection status                         :no parent proxy or
> unknown
> Origin server connection status                        :no server
> connection needed
>
> but you might be already familiar with it and not exactly what you need.
>
>
> On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org> wrote:
>
>> Perhaps use the X-Debug header:
>> https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/
>> plugins/xdebug.en.html
>> and maybe a global header_rewrite rule to add the magic header to make
>> the debug part appear?
>>
>> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
>> <be...@gmail.com> wrote:
>> > Sorry if this has been asked before, but I couldn't find it in the docs.
>> >
>> > I'm using ATS as a forward proxy. Is there a way to add a response
>> header to
>> > tell me if the request was a HIT or a MISS?
>> >
>> > Something like: X-Cache: HIT
>> >
>> > Thanks in advance,
>> > Benjamin
>>
>
>
>

Re: Cache HIT/MISS header

Posted by Igor Cicimov <ig...@encompasscorporation.com>.
You can use the Via header:

##############################################################################
# Via: headers. Docs:
#
https://docs.trafficserver.apache.org/records.config#proxy-config-http-insert-response-via-str
##############################################################################
CONFIG proxy.config.http.insert_request_via_str INT 1
CONFIG proxy.config.http.insert_response_via_str INT 3
CONFIG proxy.config.http.response_via_str STRING ATS

that will insert values like below that you can decode:

# traffic_via  '[cHs f ]'
Via header is [cHs f ], Length is 8
Via Header Details:
*Result of Traffic Server cache lookup for URL          :in cache, fresh (a
cache "HIT")*
Response information received from origin server       :no server
connection needed
Result of document write-to-cache:                     :no cache write
performed

for detailed stats (insert_response_via_str INT 3):

# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
Via Header Details:
Request headers received from client                   :simple request (not
conditional)
*Result of Traffic Server cache lookup for URL          :in cache, fresh (a
cache "HIT")*
Response information received from origin server       :no server
connection needed
Result of document write-to-cache:                     :no cache write
performed
Proxy operation result                                 :unknown
Error codes (if any)                                   :no error
Tunnel info                                            :no tunneling
Cache Type                                             :cache
*Cache Lookup Result                                    :cache hit*
ICP status                                             :no icp
Parent proxy connection status                         :no parent proxy or
unknown
Origin server connection status                        :no server
connection needed

but you might be already familiar with it and not exactly what you need.


On Tue, Dec 12, 2017 at 11:11 AM, Miles Libbey <ml...@apache.org> wrote:

> Perhaps use the X-Debug header:
> https://docs.trafficserver.apache.org/en/7.1.x/admin-
> guide/plugins/xdebug.en.html
> and maybe a global header_rewrite rule to add the magic header to make
> the debug part appear?
>
> On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
> <be...@gmail.com> wrote:
> > Sorry if this has been asked before, but I couldn't find it in the docs.
> >
> > I'm using ATS as a forward proxy. Is there a way to add a response
> header to
> > tell me if the request was a HIT or a MISS?
> >
> > Something like: X-Cache: HIT
> >
> > Thanks in advance,
> > Benjamin
>

Re: Cache HIT/MISS header

Posted by Miles Libbey <ml...@apache.org>.
Perhaps use the X-Debug header:
https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/xdebug.en.html
and maybe a global header_rewrite rule to add the magic header to make
the debug part appear?

On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
<be...@gmail.com> wrote:
> Sorry if this has been asked before, but I couldn't find it in the docs.
>
> I'm using ATS as a forward proxy. Is there a way to add a response header to
> tell me if the request was a HIT or a MISS?
>
> Something like: X-Cache: HIT
>
> Thanks in advance,
> Benjamin