4

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.

Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
Golak Sarangi
  • 809
  • 7
  • 22

2 Answers2

3

As far as I understand, most User Agents will parse Trailers, but not process them.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • Then what is the use of trailers ?? So does that mean that browsers don't support it. – Golak Sarangi Feb 26 '14 at 08:39
  • 1
    The use case is described as per the spec. Sometimes specs and implementations are out of sync. One way to address this is to fix the browsers, another one to remove the feature from the spec. – Julian Reschke Feb 26 '14 at 10:44
1

Set-Cookie is one of the headers disallowed by the spec.

So your browser will parse it, but it is explicitly disregarded.

Pingless
  • 788
  • 1
  • 7
  • 9