如何检查URL是否由AMP缓存提供?

2024-05-18 14:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我将请求(python)用于:

Mobile User Agent - Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36

这是一个AMP URL-https://www.whats-on-netflix.com/news/harry-potter-movies-netflix-2020/amp/

response.header是:

{‘Date’: ‘Wed, 20 Jan 2021 03:20:36 GMT’, ‘Content-Type’: ‘text/html; charset=UTF-8’, ‘Transfer-Encoding’: ‘chunked’, ‘Connection’: ‘keep-alive’, ‘Set-Cookie’: ‘__cfduid=d7e443a8d90cded562959a8767b6aab931611112836; expires=Fri, 19-Feb-21 03:20:36 GMT; path=/; domain=.whats-on-netflix.com; HttpOnly; SameSite=Lax; Secure’, ‘Last-Modified’: ‘Tue, 19 Jan 2021 21:12:03 GMT’, ‘Cache-Control’: ‘public, max-age=7776000’, ‘Expires’: ‘Tue, 20 Apr 2021 03:20:36 GMT’, ‘Vary’: ‘Accept-Encoding,User-Agent,Accept-Encoding’, ‘CF-Cache-Status’: ‘DYNAMIC’, ‘cf-request-id’: ’07bf6804390000dca13096e000000001′, ‘Expect-CT’: ‘max-age=604800, report-uri=”https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”‘, ‘Report-To’: ‘{“endpoints”:[{“url”:”https:\\/\\/a.nel.cloudflare.com\\/report?s=EBLDIer3oL87%2FzpNM0LSs0%2Fv7p3IdQLyxy%2Fn19V%2B1loHbRRpKrY33jbQPojeGf%2BVE84VzHXtbL%2FseQ3Y9YpX8X4j2qpljJQgz6mVTv%2BeO05BmgVP7xBLEFo%3D”}],”group”:”cf-nel”,”max_age”:604800}’, ‘NEL’: ‘{“report_to”:”cf-nel”,”max_age”:604800}’, ‘Strict-Transport-Security’: ‘max-age=0; preload’, ‘X-Content-Type-Options’: ‘nosniff’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘6145a919fbd4dca1-MAA’, ‘Content-Encoding’: ‘gzip’}

这是来自同一站点的非AMP URL-https://www.whats-on-netflix.com/whats-new/

response.header输出为:

{‘Date’: ‘Wed, 20 Jan 2021 03:22:58 GMT’, ‘Content-Type’: ‘text/html; charset=UTF-8’, ‘Transfer-Encoding’: ‘chunked’, ‘Connection’: ‘keep-alive’, ‘Set-Cookie’: ‘__cfduid=df0951d84755de428221422eb1ac491631611112978; expires=Fri, 19-Feb-21 03:22:58 GMT; path=/; domain=.whats-on-netflix.com; HttpOnly; SameSite=Lax; Secure’, ‘Last-Modified’: ‘Tue, 19 Jan 2021 16:37:34 GMT’, ‘Cache-Control’: ‘public, max-age=7776000’, ‘Expires’: ‘Tue, 20 Apr 2021 03:22:58 GMT’, ‘Vary’: ‘Accept-Encoding,User-Agent,Accept-Encoding’, ‘CF-Cache-Status’: ‘DYNAMIC’, ‘cf-request-id’: ’07bf6a2fff0000df538da69000000001′, ‘Expect-CT’: ‘max-age=604800, report-uri=”https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”‘, ‘Report-To’: ‘{“endpoints”:[{“url”:”https:\\/\\/a.nel.cloudflare.com\\/report?s=QKFl%2FTQTZvtieurNFr6Krrkc%2BJXUFNPUiMc7ikJQGvUUFgpj%2FQ6SBOXZSiksAcRCXmowGPDJyeLNBDEw%2F4eBOo2pnWYHoF0scayNWXHEHpU0xOi%2Bv1CB0So%3D”}],”group”:”cf-nel”,”max_age”:604800}’, ‘NEL’: ‘{“max_age”:604800,”report_to”:”cf-nel”}’, ‘Strict-Transport-Security’: ‘max-age=0; preload’, ‘X-Content-Type-Options’: ‘nosniff’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘6145ac933f36df53-BOM’, ‘Content-Encoding’: ‘gzip’}

它看起来是一样的,那么如何区分URL是否是从AMP缓存提供的呢

目标:如果没有从AMP缓存中提供URL,我将使用请求强制缓存URL。我目前正在使用LiteSpeed缓存,我使用了类似的方法,检查响应头中是否有子字符串“'X-LiteSpeed-Cache':'hit'”?


Tags: httpsreportcomurlcacheagecontentcloudflare

热门问题