Using trailer I am trying to set a cookie after the page streaming has started. the code below tries to set the cookie. It seems to return proper response but the cookie is not getting set in the browser(ff and 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;
The response
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
I am doing something wrong here. Need help in finding it.