本文介绍了如果修改了 - HTTP协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的浏览器使用缓存(本地缓存),它是否保证它发送的每个HTTP请求都包含IF MODIFIED SINCE标题行?

If my browser uses cache (local cache), does it GUARANTEE that each HTTP request it sends contains "IF MODIFIED SINCE" header line?

如果没有,如何我会定义它会吗?如果我将代理服务器定义到浏览器怎么办?它会自动添加吗?

If not, how do I define that it will ? and what if I define a proxy server to the browser ? will it add it automatically then?

提前谢谢

推荐答案

我正在努力解决这个问题我的RESTful Web服务并针对特定资源运行了一些测试。首先,我试图通过在资源的HTTP响应上设置以下HTTP标头来控制我的Web服务器中的浏览器缓存:

I was just working on this with my RESTful web service and ran a few tests for a particular resource. First of all I was trying to control the browser cache from my web server by setting the following HTTP headers on the HTTP response for the resource:

Cache-Control: must-revalidate, max-age=30
Last-Modified: Mon May 19 11:21:05 GMT 2014
Expires: Mon May 19 11:51:05 GMT 2014

然后从我的网页用户界面我有一个定时器(每5秒钟)对GET进行一次定时器我说的资源是可缓存的。由于浏览器缓存中的资源尚未过期,因此从浏览器缓存中提供资源的GET请求,但是,一旦max-age到期,下一个GET请求就会转到服务器并且浏览器会添加如果 -Modified-自带有Last-Modified日期的标题为这样的值:

Then from my web UI I have a timer that periodically (every 5 seconds) does a GET on the resource that I've said is cacheable. Since the resource in the browser cache has not yet expired the GET request for the resource is served from the browser cache, however, once the "max-age" has expired the next GET request goes to the server and the browser adds the "If-Modified-Since" header with the "Last-Modified" date as the value like this:

[GET] - /cms_cm_web/api/notification
referer: http://localhost:8080/cms_ui/#/
accept: application/json, text/plain, */*
accept-language: en-us
ua-cpu: AMD64
accept-encoding: gzip, deflate
user-agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
host: localhost:8080
if-modified-since: Mon, May 19 11:21:05 GMT 2014
connection: Keep-Alive

这来自IE9浏览器。我也从最新的Firefox和Chrome浏览器中获得相同的信息。
从此处服务器可以查找If-Modified-Since标头,如果确定资源未被修改,则返回304 Not Modified响应,否则返回200 OK的资源表示响应。

This came from IE9 browser. I get the same from latest Firefox and Chrome browsers as well.From here the server can look for the "If-Modified-Since" header and if it determines the resource has not been modified then it returns a 304 Not Modified response, otherwise, it returns the resource representation with a 200 OK response.

因此根据HTTP规范,您可以使用Expires和/或Cache-Control标头以及Last-Modified标头来控制缓存。这将导致浏览器缓存执行所谓的条件GET请求,因为它包含If-Modified-Since标头。

so according to the HTTP specification you can control caching using "Expires" and/or "Cache-Control" headers together with a "Last-Modified" header. This will cause the browser cache to perform what's called a "conditional GET" request as it includes the "If-Modified-Since" header.

这篇关于如果修改了 - HTTP协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:50