1 var http = require('http')
2 , assert = require('assert')
3 , request = require('../index')
6 var server = http.createServer(function (req, resp) {
8 if (req.url === '/get') {
9 assert.equal(req.method, 'GET')
14 if (req.url === '/put') {
16 assert.equal(req.method, 'PUT')
17 req.on('data', function (chunk) {
20 req.on('end', function () {
21 assert.equal(x, 'content')
27 if (req.url === '/proxy') {
28 assert.equal(req.method, 'PUT')
29 return req.pipe(request('http://localhost:8080/put')).pipe(resp)
32 if (req.url === '/test') {
33 return request('http://localhost:8080/get').pipe(request.put('http://localhost:8080/proxy')).pipe(resp)
35 throw new Error('Unknown url', req.url)
36 }).listen(8080, function () {
37 request('http://localhost:8080/test', function (e, resp, body) {
39 if (resp.statusCode !== 200) throw new Error('statusCode not 200 ' + resp.statusCode)
40 assert.equal(body, 'success')