Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

40 рядки
920 B

  1. var server = require('./server')
  2. , events = require('events')
  3. , stream = require('stream')
  4. , assert = require('assert')
  5. , fs = require('fs')
  6. , request = require('../main.js')
  7. , path = require('path')
  8. , util = require('util')
  9. ;
  10. var port = 6768
  11. , called = false
  12. , proxiedHost = 'google.com'
  13. ;
  14. var s = server.createServer(port)
  15. s.listen(port, function () {
  16. s.on('http://google.com/', function (req, res) {
  17. called = true
  18. assert.equal(req.headers.host, proxiedHost)
  19. res.writeHeader(200)
  20. res.end()
  21. })
  22. request ({
  23. url: 'http://'+proxiedHost,
  24. proxy: 'http://localhost:'+port
  25. /*
  26. //should behave as if these arguments where passed:
  27. url: 'http://localhost:'+port,
  28. headers: {host: proxiedHost}
  29. //*/
  30. }, function (err, res, body) {
  31. s.close()
  32. })
  33. })
  34. process.on('exit', function () {
  35. assert.ok(called, 'the request must be made to the proxy server')
  36. })