~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-onelineproxy.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 http = require('http')
 
2
  , assert = require('assert')
 
3
  , request = require('../index')
 
4
  ;
 
5
 
 
6
var server = http.createServer(function (req, resp) {
 
7
  resp.statusCode = 200
 
8
  if (req.url === '/get') {
 
9
    assert.equal(req.method, 'GET')
 
10
    resp.write('content')
 
11
    resp.end()
 
12
    return
 
13
  }
 
14
  if (req.url === '/put') {
 
15
    var x = ''
 
16
    assert.equal(req.method, 'PUT')
 
17
    req.on('data', function (chunk) {
 
18
      x += chunk
 
19
    })
 
20
    req.on('end', function () {
 
21
      assert.equal(x, 'content')
 
22
      resp.write('success')
 
23
      resp.end()
 
24
    })
 
25
    return
 
26
  }
 
27
  if (req.url === '/proxy') {
 
28
    assert.equal(req.method, 'PUT')
 
29
    return req.pipe(request('http://localhost:8080/put')).pipe(resp)
 
30
  }
 
31
 
 
32
  if (req.url === '/test') {
 
33
    return request('http://localhost:8080/get').pipe(request.put('http://localhost:8080/proxy')).pipe(resp)
 
34
  }
 
35
  throw new Error('Unknown url', req.url)
 
36
}).listen(8080, function () {
 
37
  request('http://localhost:8080/test', function (e, resp, body) {
 
38
    if (e) throw e
 
39
    if (resp.statusCode !== 200) throw new Error('statusCode not 200 ' + resp.statusCode)
 
40
    assert.equal(body, 'success')
 
41
    server.close()
 
42
  })
 
43
})
 
44
 
 
45
 
 
46