【问题标题】:Etag missing with curl but present in browser request卷曲缺少 Etag,但出现在浏览器请求中
【发布时间】:2014-06-24 18:57:24
【问题描述】:

我在 rails 4.0.3 / unicorn 下有一个葡萄 api。

如果我使用 curl 发出请求,那么返回的“etag”似乎丢失了。但是如果我对'swagger UI'做同样的事情,那么etag就会出现在下一个请求中,缓存也会起作用。

在浏览器中:

-第一个请求:

Status Code:200 OK
Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json
Date:Tue, 24 Jun 2014 18:43:09 GMT
Etag:"42ab9ced8f83b39e29775b0ca9cc5a6d"

-第二次请求:

Status Code:304 Not Modified
Cache-Control:max-age=0, private, must-revalidate, no-transform
Connection:keep-alive
Date:Tue, 24 Jun 2014 18:43:25 GMT
Etag:"42ab9ced8f83b39e29775b0ca9cc5a6d"
Status:304 Not Modified

我无法用 curl 检查所有这些,因为这是我收到的标题:

curl -I --header "Authorization:d0294f288597e5979a5655a70ec63b88e" http://.../products.json

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-length: 586957
Content-Type: application/json
Date: Tue, 24 Jun 2014 18:53:34 GMT
Status: 200 OK
Vary: Accept-Encoding
X-Request-Id: 89ec37ea-e675-4c24-8c16-0f2338aafe81
X-Runtime: 0.496127
Connection: keep-alive

如果我向应用程序的根目录发出 curl 请求,则返回 ETAG:

curl -I --header "Authorization:d0294f288597e5979a5655a70ec63b88" http://...

HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-length: 3359
Content-Type: text/html; charset=utf-8
Date: Tue, 24 Jun 2014 18:54:13 GMT
Etag: "c9198615bdab1e5ef77bfb9a6890f576"

欢迎任何解释......似乎葡萄正在去除卷曲的ETAG......(但这不可能发生......显然......)

【问题讨论】:

  • 我希望我明白这个 ETag 响应标头是从哪里来的,而且大摇大摆。我不确定是什么设置了响应标头...swagger 只是一堆静态文件。

标签: curl ruby-on-rails-4 grape-api


【解决方案1】:

curl -我改变了服务器的行为,所以我使用'curl -v'。这样就可以正确返回 etag + 缓存工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-30
    • 2018-09-20
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多