Sha256: fd747389ec5df55bdde63126f78e6b012fae67e9cd459723868c4a67637391e5

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

var server = require('./server')
  , assert = require('assert')
  , request = require('../main.js')
  , Cookie = require('../vendor/cookie')
  , Jar = require('../vendor/cookie/jar')
  , s = server.createServer()

s.listen(s.port, function () {
  var serverUri = 'http://localhost:' + s.port
    , numTests = 0
    , numOutstandingTests = 0

  function createTest(requestObj, serverAssertFn) {
    var testNumber = numTests;
    numTests += 1;
    numOutstandingTests += 1;
    s.on('/' + testNumber, function (req, res) {
      serverAssertFn(req, res);
      res.writeHead(200);
      res.end();
    });
    requestObj.url = serverUri + '/' + testNumber
    request(requestObj, function (err, res, body) {
      assert.ok(!err)
      assert.equal(res.statusCode, 200)
      numOutstandingTests -= 1
      if (numOutstandingTests === 0) {
        console.log(numTests + ' tests passed.')
        s.close()
      }
    })
  }

  // Issue #125: headers.cookie shouldn't be replaced when a cookie jar isn't specified
  createTest({headers: {cookie: 'foo=bar'}}, function (req, res) {
    assert.ok(req.headers.cookie)
    assert.equal(req.headers.cookie, 'foo=bar')
  })

  // Issue #125: headers.cookie + cookie jar
  var jar = new Jar()
  jar.add(new Cookie('quux=baz'));
  createTest({jar: jar, headers: {cookie: 'foo=bar'}}, function (req, res) {
    assert.ok(req.headers.cookie)
    assert.equal(req.headers.cookie, 'foo=bar; quux=baz')
  })

  // There should be no cookie header when neither headers.cookie nor a cookie jar is specified
  createTest({}, function (req, res) {
    assert.ok(!req.headers.cookie)
  })
})

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
vulcan-0.8.2 server/node_modules/cradle/node_modules/request/tests/test-headers.js
vulcan-0.8.1 server/node_modules/cradle/node_modules/request/tests/test-headers.js
iron_worker_ng-0.10.1 iron_worker_examples/binary/phantom-nodejs/node_modules/iron_worker/node_modules/iron_core/node_modules/request/tests/test-headers.js
vulcan-0.8.0 server/node_modules/cradle/node_modules/request/tests/test-headers.js
vulcan-0.7.2 server/node_modules/cradle/node_modules/request/tests/test-headers.js
vulcan-0.7.1 server/node_modules/cradle/node_modules/request/tests/test-headers.js
vulcan-0.7.0 server/node_modules/cradle/node_modules/request/tests/test-headers.js