~cordova-ubuntu/cordova-cli/trunk

« back to all changes in this revision

Viewing changes to node_modules/cordova/_vendor/request/2.22.0/tests/test-proxy.js

  • Committer: Robert Bruce Park
  • Date: 2014-02-26 21:27:56 UTC
  • mfrom: (44.1.5 3.4-release)
  • Revision ID: robert.park@canonical.com-20140226212756-6jmoiqugw0f1ebxb
Update to 3.4.0 stable release.

Show diffs side-by-side

added added

removed removed

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