使用预告片我试图在页面流媒体开始后设置一个cookie。下面的代码试图设置cookie。它似乎返回了正确的响应,但cookie没有在浏览器中设置(ff和chrome)。
var express = require('express'),
http = require('http'),
app = express(),
server;
app.use(app.router);
app.all('*', function(req, res) {
res.setHeader('Trailer', 'Set-Cookie');
res.setHeader('Content-Type', 'text/plain');
res.write("hi this is ogkla");
res.addTrailers({
'Set-Cookie': "val=ogkla"
});
res.end();
});
server = http.createServer(app).listen(80);
module.exports = server;
回复
curl -iv --raw 'http://localhost/'
* Adding handle: conn: 0x7fd87180aa89
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd87180aa89) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 80 (#0)
* Trying ::1...
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< X-Powered-By: Express
X-Powered-By: Express
< Trailer: Set-Cookie
Trailer: Set-Cookie
< Content-Type: text/plain
Content-Type: text/plain
< Date: Wed, 26 Feb 2014 06:45:43 GMT
Date: Wed, 26 Feb 2014 06:45:43 GMT
< Connection: keep-alive
Connection: keep-alive
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
<
10
hi this is ogkla
0
Set-Cookie: val=ogkla
* Connection #0 to host localhost left intact
我在这里做错了。需要帮助才能找到它。
答案 0 :(得分:3)
据我了解,大多数用户代理将解析预告片,但不处理它们。
答案 1 :(得分:1)
Set-Cookie
是标头disallowed by the spec之一。
因此,您的浏览器将对其进行解析,但将其明确忽略。