我在这里发现了几个相关问题
- Apache ignoring PHP headers when sending a 304
- 304 response does not set custom header for apache with mod_headers
我也尝试做的是为我的同步服务实现拉取请求处理程序,该处理程序告诉数据库中任何用户的对象是否有任何更改。如果进行了更改,我会用对象名称及其 ID 列表进行响应。如果没有更改,我会发送 304 Not Modified
响应。
为了控制这些请求的频率,我想到了在所有响应中添加 Retry-After
header 。问题是 Apache 在发送 304 响应时剪切了所有 header 。
根据RFC2616
If the conditional GET used a strong cache validator (see section 13.3.3), the response SHOULD NOT include other entity-headers.
但是 Retry-After 不是实体 header 。我是不是错了或者遗漏了什么?
有什么解决办法吗?
如果无法解决此问题(带有 Retry-After header 的 304 响应),在这种情况下还有哪些其他选择?使用 204 No Content
代替 304 Not Modified
似乎合理吗?
最佳答案
事实证明,Apache 会针对 hard-coded set 过滤 304 Not Modified 响应标题名称。对于 2.2.x 版本,它们是:
Connection, Keep-Alive, ETag, Content-Location, Expires, Cache-Control, Vary, Warning, WWW-Authenticate, Proxy-Authenticate, Set-Cookie, Set-Cookie2
一种解决方法是重载该列表中的 header 。例如,您可以滥用警告 header :
header("Warning: X-Retry-After: 60"); //tested on Apache 2.2.3 / PHP5.1.6
另请参阅:Putting detailed REST error message in HTTP Warning header, good/bad idea?
注意:尽管 Apache 已实现,RFC2616 似乎表明 Retry-After 对于 304 响应来说是合理的:
... This field MAY also be used with any 3xx (Redirection) response to indicate the minimum time the user-agent is asked wait before issuing the redirected request. ...
关于http - 304 Not Modified 上的 Retry-After 响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9429695/