共计 1720 个字符,预计需要花费 5 分钟才能阅读完成。
问题
Nginx 配置了缓存 发现 Java HttpClient 调用后 再次 curl 调用 却没有走缓存
Nginx-Cache: MISS
起因
抓包进行比拟
tcpdump tcp -i utun1 -tttt -s 0 and host api.ceicdata.com -vvvv
curl
2020-09-26 22:00:22.881052 IP (tos 0x2,ECT(0), ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 342)
10.9.8.22.64092 > api.ceicdata.com.http: Flags [P.], cksum 0xfc9b (correct), seq 1:291, ack 1, win 2055, options [nop,nop,TS val 1025591764 ecr 3641213951], length 290: HTTP, length: 290
GET /v2//layout/tables/TB2992477/series HTTP/1.1
Host: api.ceicdata.com
User-Agent: curl/7.54.0
Accept: */*
HttpClient
10.9.8.22.64107 > api.ceicdata.com.http: Flags [P.], cksum 0xec15 (correct), seq 1:362, ack 1, win 2055, options [nop,nop,TS val 1025669827 ecr 3641292174], length 361: HTTP, length: 361
GET /v2//layout/tables/TB2992467/series HTTP/1.1
Host: api.ceicdata.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_192)
Accept-Encoding: gzip,deflate
HttpClient 多了一个 Accept-Encoding
而后试了下 curl 加上Accept-Encoding
之后 能走之前 HttpClient 已有的缓存
curl -i -H 'Accept-Encoding: gzip,deflate' http://api.ceicdata.com/v2//layout/tables/TB2992487/series
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 26 Sep 2020 14:05:11 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
x-amzn-RequestId: ce450462-d0d5-4db9-b681-0e4ddc0b3e7b
Access-Control-Allow-Origin: *
x-amzn-Remapped-Content-Length: 21530
x-amzn-Remapped-Connection: keep-alive
x-amz-apigw-id: TeiLeEEWoAMFsKw=
x-amzn-Remapped-Date: Sat, 26 Sep 2020 14:03:53 GMT
X-Cache: Miss from cloudfront
Via: 1.1 25a6a41477f0a4b161961d1300fb0714.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: SIN2-C1
X-Amz-Cf-Id: gSWgf1KXJG2DvZcgggLlo6Tr2EgAW8X9beUJDjnOLFgN1CAAHKCikw==
Content-Encoding: gzip
Expires: Sat, 26 Sep 2020 15:05:11 GMT
Cache-Control: max-age=3600
Nginx-Cache: HIT
不同的 Accept-Encoding 保留在不同的文件中
参考文档
https://stackoverflow.com/que…
正文完