set_header.js 782 B

12345678910111213141516171819202122232425262728293031
  1. var test = require('tape');
  2. var http = require('http');
  3. var hyperquest = require('../');
  4. var through = require('through2');
  5. test('setHeader on a request', function (t) {
  6. t.plan(2);
  7. var server = http.createServer(function (req, res) {
  8. t.equal(req.headers.robot, 'party');
  9. res.end('beep boop');
  10. });
  11. server.listen(0, function () {
  12. var port = server.address().port;
  13. check(t, port);
  14. });
  15. t.on('end', server.close.bind(server));
  16. });
  17. function check (t, port) {
  18. var r = hyperquest('http://localhost:' + port);
  19. r.setHeader('robot', 'party');
  20. r.pipe(through(write, end));
  21. var data = '';
  22. function write (buf, enc, cb) { data += buf; cb() }
  23. function end () {
  24. t.equal(data, 'beep boop');
  25. }
  26. }