Edited at

curlコマンドでアカマイのレスポンスヘッダを取得する

More than 3 years have passed since last update.

普通に実行すると、アカマイのヘッダは返ってこない。

$ curl -I https://www.buyma.us/

HTTP/1.1 200 OK

Cache-Control: max-age=0, private, must-revalidate
Content-Length: 100224
Content-Type: text/html; charset=utf-8
ETag: W/"bc855dac72793ad6604823ccda3d8226"
Server: nginx
Status: 200 OK
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN


アカマイのレスポンスヘッダを取得したい場合

$ curl -H \

"Pragma: akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no" \
-IXGET https://www.buyma.us/

HTTP/1.1 200 OK

Cache-Control: max-age=0, private, must-revalidate
Content-Type: text/html; charset=utf-8
ETag: W/"73571fe6da3e8f52838c5e64c3a25b47"
Server: nginx
Status: 200 OK
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Cache: TCP_MISS from a72-246-190-192.deploy.akamaitechnologies.com (AkamaiGHost/7.4.0-16212965) (-)
X-Cache-Key: S/D/1146/397919/000/www-origin.buyma.us/
X-True-Cache-Key: /D/000/www-origin.buyma.us/
X-Akamai-Session-Info: name=AKA_PM_BASEDIR; value=
X-Akamai-Session-Info: name=AKA_PM_CACHEABLE_OBJECT; value=false
X-Akamai-Session-Info: name=AKA_PM_FWD_URL; value=/
X-Akamai-Session-Info: name=AKA_PM_NETSTORAGE_ROOT; value=
X-Akamai-Session-Info: name=AKA_PM_PREFETCH_ON; value=true
X-Akamai-Session-Info: name=AKA_PM_RUM_ENABLED; value=on
X-Akamai-Session-Info: name=AKA_PM_SR_ENABLED; value=true
X-Akamai-Session-Info: name=AKA_PM_SR_NODE_ID; value=0
X-Akamai-Session-Info: name=AKA_PM_TD_ENABLED; value=true
X-Akamai-Session-Info: name=AKA_PM_TD_MAP_PREFIX; value=ch
X-Akamai-Session-Info: name=FASTTCP_RENO_FALLBACK_DISABLE_OPTOUT; value=on
X-Akamai-Session-Info: name=OVERRIDE_HTTPS_IE_CACHE_BUST; value=all
X-Akamai-Session-Info: name=RANDOM_SAMPLE; value=false
X-Akamai-Session-Info: name=STRICT_BASELINE_V1ARL_CHECKS; value=<<ENCRYPTED>>
X-Akamai-Session-Info: name=TCP_OPT_APPLIED; value=low
X-Serial: 1146
X-Check-Cacheable: NO


キャッシュ設定の動作を最低限確認したい場合

$ curl -s -H "Pragma: akamai-x-cache-on, akamai-x-check-cacheable, akamai-x-get-true-cache-key" -IXGET https://www.buyma.us/

HTTP/1.1 200 OK

Cache-Control: max-age=0, private, must-revalidate
Content-Type: text/html; charset=utf-8
ETag: W/"ab44b734d78a8c6cc368d0fd7961817c"
Server: nginx
Status: 200 OK
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Check-Cacheable: NO
X-Cache: TCP_MISS from a72-246-190-192.deploy.akamaitechnologies.com (AkamaiGHost/7.4.0-16212965) (-)
X-True-Cache-Key: /D/000/www-origin.buyma.us/

X-Check-Cacheable
YESならアカマイでキャッシュされ、NOならキャッシュされない

X-True-Cache-Key
アカマイのCache ID

X-Cache
下記参照

https://community.akamai.com/community/web-performance/blog/2015/03/31/using-akamai-pragma-headers-to-investigate-or-troubleshoot-akamai-content-delivery

TCP_HIT
Object was fresh in cache and object from disk cache.

TCP_MISS
Object was not in cache, server fetched object from origin.

TCP_REFRESH_HIT
Object was stale in cache and was successfully refreshed with the origin on an If-Modified-Since request.

TCP_REFRESH_MISS
Object was stale in cache and refresh obtained a new object from origin in response to our IF-Modified-Since request.

TCP_REFRESH_FAIL_HIT
Object was stale in cache and failed on refresh (couldn't reach origin) so the stale object was served .

TCP_IMS_HIT
IF-Modified-Since request from client and object was fresh in cache and served.

TCP_NEGATIVE_HIT
Object previously returned a "not found" (or any other negatively cacheable response) and that cached response was a hit for this new request.

TCP_MEM_HIT
Object was on disk and in the memory cache. Server served it without hitting the disk. 


レスポンスボディも含めて確認したい場合

以下の場合はレスポンスヘッダは標準エラー出力で返されるので、grepしたい場合は2>&1のようにする必要がある。

$ curl -s -v -H "Pragma: akamai-x-cache-on, akamai-x-check-cacheable, akamai-x-get-true-cache-key" https://www.buyma.us/ 2>&1 |

egrep '(X-Check-Cacheable:|X-Cache:|X-True-Cache-Key:|meta charset)'

< X-Cache: TCP_MISS from a96-7-251-113.deploy.akamaitechnologies.com (AkamaiGHost/7.3.4.1-16162558) (-)

< X-True-Cache-Key: /D/000/www-origin.buyma.us/
< X-Check-Cacheable: NO
<!DOCTYPE html><html><head><meta charset="UTF-8" />


ブラウザから取得したい場合