来自HTML5 AppCache的请求没有设置referer标头

时间:2014-01-07 23:38:31

标签: html5 html5-appcache offline-caching cache-manifest

我遇到了HTML5 AppCache及其发送的请求的问题,所以我写了一个小问题的演示。首先,有两个HTML文件。一个叫withmanifest.html,看起来像这样:

<html manifest="hello.appcache">
<body>
    Hello world
    <script src="client.js"></script>
</body>
</html>

第二个HTML文件名为withoutmanifest.html,除了省略manifest属性外,完全相同。 client.js文件只是一行 - 它没有做任何有趣的事情。 hello.appcache文件缓存client.js

我创建了一个简单的node.js服务器(server.js)来为目录中的静态文件提供服务,并为每个请求记录URL和referer标头:

http = require('http');
nodeStatic = require('node-static');

var staticFileServer = new nodeStatic.Server('./', {cache: 0});

http.createServer(function(req, res) {
  console.log(req.url + ' ' + (req.headers['referer'] || 'None'));
  req.addListener('end', function() {
    staticFileServer.serve(req, res);
  }).resume();
}).listen(8000);

完整代码(总共约50行)可用on github

在Chrome中,没有设置AppCache(chrome:// appcache-internals为空),我加载/withoutmanifest.html并获取以下日志:

/withoutmanifest.html None
/client.js http://localhost:8000/withoutmanifest.html
/favicon.ico None

然后我加载/withmanifest.html并获取以下日志:

/withmanifest.html None
/hello.appcache None
/client.js http://localhost:8000/withoutmanifest.html
/client.js None
/withmanifest.html None
/hello.appcache None

client.js的第二个请求由AppCache更新进程发送,不包含引用标头。这是一个问题,因为我真正想要做的是查询另一台服务器,如果请求没有引用,那么该服务器会返回错误。我不确定下一步该做什么 - 对我来说,AppCache会从页面本身发送不同的请求似乎很奇怪。有没有办法设置referer标头?

0 个答案:

没有答案