HTTP If-Modified-Since 以毫秒为单位

标签 http http-headers

假设我从 REST Web 服务获取一个对象,并且该对象有一个时间戳。这个时间戳有一个毫秒部分。下次我请求同一个对象时,我不希望它被返回,除非它已经改变,所以我使用 If-Modified-Since header 。但是该 header 中的日期甚至不应该有毫秒。如果我将时间戳向下舍入,我将始终取回对象,就好像它总是被修改一样。如果我将它四舍五入,我可能会错过一些更新。在这种情况下,If-Modified-Since header 对我来说完全没用,还是我遗漏了什么?

最佳答案

发送毫秒时间戳的服务不符合 HTTP 标准。 Last-Modified必须作为 HTTP-date 发送 §3.3.1非常清楚地指定:

HTTP-date    = rfc1123-date | rfc850-date | asctime-date
rfc1123-date = wkday "," SP date1 SP time SP "GMT"
rfc850-date  = weekday "," SP date2 SP time SP "GMT"
asctime-date = wkday SP date3 SP time SP 4DIGIT
date1        = 2DIGIT SP month SP 4DIGIT
              ; day month year (e.g., 02 Jun 1982)
date2        = 2DIGIT "-" month "-" 2DIGIT
              ; day-month-year (e.g., 02-Jun-82)
date3        = month SP ( 2DIGIT | ( SP 1DIGIT ))
              ; month day (e.g., Jun  2)
time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
              ; 00:00:00 - 23:59:59
wkday        = "Mon" | "Tue" | "Wed"
            | "Thu" | "Fri" | "Sat" | "Sun"
weekday      = "Monday" | "Tuesday" | "Wednesday"
            | "Thursday" | "Friday" | "Saturday" | "Sunday"
month        = "Jan" | "Feb" | "Mar" | "Apr"
            | "May" | "Jun" | "Jul" | "Aug"
            | "Sep" | "Oct" | "Nov" | "Dec"

提交您正在使用的服务的错误。以毫秒发送Last-ModifiedIf-Modified-Since是无效的。

如果亚秒精度很重要,使用 entity tags (ETag) 可能更合适.

关于HTTP If-Modified-Since 以毫秒为单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18603154/

相关文章:

php - 在屏幕上打印响应标题的消息

wordpress - 利用浏览器缓存不起作用 - Htaccess 和 mod_expires Active

http - Servlet 反射跨站脚本漏洞

html - 我如何从网页或 URL 知道地理来源?

rest - 普通 HTTP 请求和 REST 请求有什么区别

多个站点之间的 HTTP session

http-headers - JMeter 在测试期间更改 HTTP header

javascript - 使用 Javascript 发出 HTTP POST 身份验证基本请求

ios - 向 Alamofire 请求添加 header (使用临时 session )

node.js - 如何修复( Node :12388) [DEP0066] DeprecationWarning: OutgoingMessage. prototype._headers 在 Windows 中已弃用