为什么 OkHttp 在设置 If-Modified-Since header 时会像对待 Last-Modified header 一样对待日期 header?
Why does OkHttp treat the Date header the same as it treats the Last-Modified header when setting the If-Modified-Since header?
我正在使用 Jenkins 插件,该插件使用 OkHttp 库处理与 Github API.
的集成
Github 的 /repos/:owner/:repo 端点 returns 当 OkHttp 尝试使用不允许访问资源的令牌请求资源时出现错误 404。当令牌的范围扩展到允许它访问资源时,OkHttp 使用 If-Modified-Since header 发出请求。 header 的值设置为来自 404 响应的日期 header 的值。第二个请求的响应是 HTTP 304。根据 Github 的支持团队,此行为是正确的行为,因为资源(/repos/:owner/:repo 端点后面的数据)尚未被自第一个请求发出以来修改。但是,这意味着 OkHttp 客户端现在使用缓存的 404 响应。
似乎日期 header 旨在计算新鲜度,而不是检查上次修改资源的时间。 RFC 7232 section 3.3 says that clients may use the Date header's value as the If-Modified-Since value, but I have not come across other literature on the web suggesting that this behavior is accepted. I do not see any reference to the Date header in Mozilla's documentation on the If-Modified-Since header.
Postel 定律难道不会建议 OkHttp 尽量不要滥用日期 header,将其用作 If-Modified-Since header 的另一个来源吗?
RFC 明确规定了什么行为是合适的。如果 RFC 说 Date
header 可以与 If-Modified-Since
一起使用,那么它可以。
考虑说服 GitHub 在范围扩大时使缓存失效。如果在 2017-03-01 提供了响应,并且在 2017-04-01 扩展了令牌的范围,则在 2017-04-01 有效地修改了资源。
您的另一个选择是禁用 OkHttp 的缓存。像每个缓存一样,由于遵守错误的缓存配置指令,它违反了 Postel 定律。
我正在使用 Jenkins 插件,该插件使用 OkHttp 库处理与 Github API.
的集成Github 的 /repos/:owner/:repo 端点 returns 当 OkHttp 尝试使用不允许访问资源的令牌请求资源时出现错误 404。当令牌的范围扩展到允许它访问资源时,OkHttp 使用 If-Modified-Since header 发出请求。 header 的值设置为来自 404 响应的日期 header 的值。第二个请求的响应是 HTTP 304。根据 Github 的支持团队,此行为是正确的行为,因为资源(/repos/:owner/:repo 端点后面的数据)尚未被自第一个请求发出以来修改。但是,这意味着 OkHttp 客户端现在使用缓存的 404 响应。
似乎日期 header 旨在计算新鲜度,而不是检查上次修改资源的时间。 RFC 7232 section 3.3 says that clients may use the Date header's value as the If-Modified-Since value, but I have not come across other literature on the web suggesting that this behavior is accepted. I do not see any reference to the Date header in Mozilla's documentation on the If-Modified-Since header.
Postel 定律难道不会建议 OkHttp 尽量不要滥用日期 header,将其用作 If-Modified-Since header 的另一个来源吗?
RFC 明确规定了什么行为是合适的。如果 RFC 说 Date
header 可以与 If-Modified-Since
一起使用,那么它可以。
考虑说服 GitHub 在范围扩大时使缓存失效。如果在 2017-03-01 提供了响应,并且在 2017-04-01 扩展了令牌的范围,则在 2017-04-01 有效地修改了资源。
您的另一个选择是禁用 OkHttp 的缓存。像每个缓存一样,由于遵守错误的缓存配置指令,它违反了 Postel 定律。