Discussion:
Cache HIT/MISS header
Benjamin Morel
2017-12-11 16:57:00 UTC
Permalink
*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
Miles Libbey
2017-12-12 00:11:45 UTC
Permalink
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
Post by Benjamin Morel
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
Igor Cicimov
2017-12-12 00:29:08 UTC
Permalink
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.
Post by Miles Libbey
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
Post by Benjamin Morel
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
Post by Benjamin Morel
tell me if the request was a HIT or a MISS?
Something like: X-Cache: HIT
Thanks in advance,
Benjamin
Veiko Kukk
2017-12-12 12:10:41 UTC
Permalink
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
Post by Igor Cicimov
############################################################
##################
# 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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
*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
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
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.
Post by Miles Libbey
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
Post by Benjamin Morel
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
Post by Benjamin Morel
tell me if the request was a HIT or a MISS?
Something like: X-Cache: HIT
Thanks in advance,
Benjamin
Veiko Kukk
2017-12-13 09:43:26 UTC
Permalink
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
Post by Veiko Kukk
Hi,
I recently had exact same task: to include cache status in response
* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with following
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"
Veiko
Post by Igor Cicimov
############################################################
##################
# 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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
*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
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
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.
Post by Miles Libbey
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
Post by Benjamin Morel
Sorry if this has been asked before, but I couldn't find it in the
docs.
Post by Benjamin Morel
I'm using ATS as a forward proxy. Is there a way to add a response
header to
Post by Benjamin Morel
tell me if the request was a HIT or a MISS?
Something like: X-Cache: HIT
Thanks in advance,
Benjamin
Benjamin Morel
2017-12-13 17:33:55 UTC
Permalink
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
Post by Veiko Kukk
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
Post by Veiko Kukk
Hi,
I recently had exact same task: to include cache status in response
* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with following
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"
Veiko
Post by Igor Cicimov
############################################################
##################
# 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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
*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
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
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.
Post by Miles Libbey
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
Post by Benjamin Morel
Sorry if this has been asked before, but I couldn't find it in the
docs.
Post by Benjamin Morel
I'm using ATS as a forward proxy. Is there a way to add a response
header to
Post by Benjamin Morel
tell me if the request was a HIT or a MISS?
Something like: X-Cache: HIT
Thanks in advance,
Benjamin
Veiko Kukk
2017-12-14 11:03:34 UTC
Permalink
Hi Benjamin,

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

Veiko
Post by Benjamin Morel
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
Post by Veiko Kukk
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
Post by Veiko Kukk
Hi,
I recently had exact same task: to include cache status in response
* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with following
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"
Veiko
Post by Igor Cicimov
############################################################
##################
# 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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
*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
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
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.
Post by Miles Libbey
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
Post by Benjamin Morel
Sorry if this has been asked before, but I couldn't find it in the
docs.
Post by Benjamin Morel
I'm using ATS as a forward proxy. Is there a way to add a response
header to
Post by Benjamin Morel
tell me if the request was a HIT or a MISS?
Something like: X-Cache: HIT
Thanks in advance,
Benjamin
Miles Libbey
2017-12-14 16:35:59 UTC
Permalink
On Wed, Dec 13, 2017 at 9:33 AM, Benjamin Morel
Post by Benjamin Morel
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
Post by Benjamin Morel
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
Post by Veiko Kukk
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
Post by Veiko Kukk
Hi,
I recently had exact same task: to include cache status in response
* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with following
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"
Veiko
Post by Igor Cicimov
##############################################################################
#
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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
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
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
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.
Post by Miles Libbey
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
Post by Benjamin Morel
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
Benjamin Morel
2017-12-19 11:16:15 UTC
Permalink
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 Wed, Dec 13, 2017 at 9:33 AM, Benjamin Morel
Post by Benjamin Morel
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
Post by Benjamin Morel
resulting Via header, looks like the way to go.
Apart from the obscure decoder, is there a documentation for the format
of
Post by Benjamin Morel
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
Post by Benjamin Morel
With a listing of all possible statuses (cR = fresh Ram hit, cH = fresh
hit,
Post by Benjamin Morel
...)
I couldn't find this in the doc.
Thanks in advance,
Ben
Post by Veiko Kukk
If you also need MISS (our setup does not, we know amount of requests
and
Post by Benjamin Morel
Post by Veiko Kukk
amount of HIT's), you need to add another condition with set-header
X-Cache
Post by Benjamin Morel
Post by Veiko Kukk
"MISS"
--
Veiko
Post by Veiko Kukk
Hi,
I recently had exact same task: to include cache status in response
* proxy.config.http.insert_response_via_str 2
* Using header_rewrite plugin to create additional header with
following
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
cond %{SEND_RESPONSE_HDR_HOOK} [AND]
cond %{HEADER:Via} /(\[cH|\[cR)/
set-header X-Cache "HIT"
Veiko
Post by Igor Cicimov
############################################################
##################
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
#
https://docs.trafficserver.apache.org/records.config#
proxy-config-http-insert-response-via-str
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
############################################################
##################
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
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
# traffic_via '[cHs f ]'
Via header is [cHs f ], Length is 8
Result of Traffic Server cache lookup for URL :in cache,
fresh
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
(a cache "HIT")
Response information received from origin server :no server
connection needed
Result of document write-to-cache: :no cache write
performed
# traffic_via 'uScHs f p eN:t cCHi p s '
Via header is uScHs f p eN:t cCHi p s , Length is 24
Request headers received from client :simple request
(not conditional)
Result of Traffic Server cache lookup for URL :in cache,
fresh
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
(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
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
or unknown
Origin server connection status :no server
connection needed
but you might be already familiar with it and not exactly what you
need.
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
Post by Miles Libbey
https://docs.trafficserver.apache.org/en/7.1.x/admin-
guide/plugins/xdebug.en.html
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
Post by Miles Libbey
and maybe a global header_rewrite rule to add the magic header to
make
Post by Benjamin Morel
Post by Veiko Kukk
Post by Veiko Kukk
Post by Igor Cicimov
Post by Miles Libbey
the debug part appear?
On Mon, Dec 11, 2017 at 8:57 AM, Benjamin Morel
Post by Benjamin Morel
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
James Peach
2017-12-13 19:09:21 UTC
Permalink
Post by Benjamin Morel
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
Veiko Kukk
2017-12-14 11:00:46 UTC
Permalink
Post by James Peach
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
Loading...