Jason Christa
Jason Christa

Reputation: 12508

Node.js http.ClientRequest: get raw headers

I am using Node.js 0.2.3 and response.headers['set-cookie'] seems to be truncated after the first cookie. Is there any way I can just read the raw headers?

BTW, the set-cookie header should contain:

id1=sw34rwdsfsd;secure;
id2=wer235sd2354;secure;
id3=df435df4543;secure

My guess would be it is not parsing the boolean attributes right and stops after the first one. Anyone know if this is fixed in later versions of Node.js (even though I can't upgrade just yet)?

Upvotes: 1

Views: 1558

Answers (1)

mkrecny
mkrecny

Reputation: 503

    var spawn = require('child_process').spawn;

    function getHeader(url, callback){
      var client = spawn('curl', ['-I', url]);
      client.stdout.setEncoding('***');
      client.stdout.on('data', function(data){
        callback(data);
      });
    }

The -I flag asks curl for just the header. Pass whatever encoding to setEncoding - I think it defaults to the raw that you're looking for.

Upvotes: 1

Related Questions