test-option-reuse.js 940 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var assert = require('assert')
  2. , request = require('../index')
  3. , http = require('http')
  4. ;
  5. var count = 0;
  6. var methodsSeen = {
  7. head: 0
  8. , get: 0
  9. };
  10. var s = http.createServer(function(req, res) {
  11. res.statusCode = 200;
  12. res.end('');
  13. count++;
  14. if (req.method.toLowerCase() === 'head') methodsSeen.head++;
  15. if (req.method.toLowerCase() === 'get') methodsSeen.get++;
  16. if (count < 2) return
  17. assert(methodsSeen.head === 1);
  18. assert(methodsSeen.get === 1);
  19. }).listen(6767, function () {
  20. //this is a simple check to see if the options object is be mutilated
  21. var url = 'http://localhost:6767';
  22. var options = {url: url};
  23. request.head(options, function (err, resp, body) {
  24. assert(Object.keys(options).length === 1);
  25. assert(options.url === url);
  26. request.get(options, function (err, resp, body) {
  27. assert(Object.keys(options).length === 1);
  28. assert(options.url === url);
  29. s.close();
  30. })
  31. })
  32. })