source: Dev/trunk/src/node_modules/request/tests/test-onelineproxy.js @ 484

Last change on this file since 484 was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

File size: 1.1 KB
Line 
1var http = require('http')
2  , assert = require('assert')
3  , request = require('../index')
4  ;
5
6var 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
Note: See TracBrowser for help on using the repository browser.