说服Firefox通过HTTPS发送If-Modified-Since标头

说服Firefox通过HTTPS发送If-Modified-Since标头

Convince Firefox to send an If-Modified-Since header over HTTPS

我该如何说服Firefox(如果有关系的话为3.0.1)在HTTPS请求中发送If-Modified-Since标头? 如果请求使用纯HTTP,并且我的服务器忠实地接受它,它将发送标头。 但是,当我改为使用HTTPS从同一服务器请求同一资源时(即只是将URL中的http://更改为https://),那么Firefox根本不会发送If-Modified-Since标头。 这种行为是SSL规范强制规定的吗?

这是一些使用Live HTTP Headers Firefox扩展提取的HTTP和HTTPS请求/响应对示例,其中粗体字有些不同:

HTTP请求/响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
http://myserver.com:30000/scripts/site.js

GET /scripts/site.js HTTP/1.1
Host: myserver.com:30000
User-Agent: Mozilla/5.0 (...) Gecko/2008070206 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
If-Modified-Since: Tue, 19 Aug 2008 15:57:30 GMT
If-None-Match:"a0501d1-300a-454d22526ae80"-gzip
Cache-Control: max-age=0

HTTP/1.x 304 Not Modified
Date: Tue, 19 Aug 2008 15:59:23 GMT
Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8
Connection: Keep-Alive
Keep-Alive: timeout=5, max=99
Etag:"a0501d1-300a-454d22526ae80"-gzip

HTTPS请求/响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
https://myserver.com:30001/scripts/site.js

GET /scripts/site.js HTTP/1.1
Host: myserver.com:30001
User-Agent: Mozilla/5.0 (...) Gecko/2008070206 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Date: Tue, 19 Aug 2008 16:00:14 GMT
Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8
Last-Modified: Tue, 19 Aug 2008 15:57:30 GMT
Etag:"a0501d1-300a-454d22526ae80"-gzip
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 3766
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/javascript

更新:将browser.cache.disk_cache_ssl设置为true可以解决问题(这很奇怪,因为正如Nickolay指出的那样,仍然存在内存缓存)。 向响应添加" Cache-control:public"标头也可以。 谢谢!


HTTPS requests are not cached so sending an If-Modified-Since doesn't make any sense. The not caching is a security precaution.

磁盘上不缓存是一种安全预防措施,但似乎确实会影响If-Modified-Since行为(浏览代码)。

尝试将Firefox首选项(在about:config中)将browser.cache.disk_cache_ssl设置为true。 如果有帮助,请尝试在响应中发送Cache-Control:public标头。

更新:Gecko 2.0(Firefox 4)的Firefox行为已更改-现在已缓存HTTPS内容。


HTTPS请求不会被缓存,因此发送If-Modified-Since没有任何意义。 不缓存是一种安全预防措施。


推荐阅读