|
1 | 1 | var webPasses = require('../lib/http-proxy/passes/web-incoming'), |
2 | 2 | httpProxy = require('../lib/http-proxy'), |
3 | 3 | expect = require('expect.js'), |
| 4 | + concat = require('concat-stream'), |
| 5 | + async = require('async'), |
4 | 6 | url = require('url'), |
5 | 7 | http = require('http'); |
6 | 8 |
|
@@ -316,6 +318,44 @@ describe('#createProxyServer.web() using own http server', function () { |
316 | 318 | http.request('http://127.0.0.1:8086', function() {}).end(); |
317 | 319 | }); |
318 | 320 |
|
| 321 | + it('should proxy the request and provide and respond to manual user response when using modifyResponse', function(done) { |
| 322 | + var proxy = httpProxy.createProxyServer({ |
| 323 | + target: 'http://127.0.0.1:8080', |
| 324 | + selfHandleResponse: true |
| 325 | + }); |
| 326 | + |
| 327 | + function requestHandler(req, res) { |
| 328 | + proxy.once('proxyRes', function (proxyRes, pReq, pRes) { |
| 329 | + proxyRes.pipe(concat(function (body) { |
| 330 | + expect(body.toString('utf8')).eql('Response'); |
| 331 | + pRes.end(Buffer.from('my-custom-response')); |
| 332 | + })) |
| 333 | + }); |
| 334 | + |
| 335 | + proxy.web(req, res); |
| 336 | + } |
| 337 | + |
| 338 | + var proxyServer = http.createServer(requestHandler); |
| 339 | + |
| 340 | + var source = http.createServer(function(req, res) { |
| 341 | + res.end('Response'); |
| 342 | + }); |
| 343 | + |
| 344 | + async.parallel([ |
| 345 | + next => proxyServer.listen(8086, next), |
| 346 | + next => source.listen(8080, next) |
| 347 | + ], function (err) { |
| 348 | + http.get('http://127.0.0.1:8086', function(res) { |
| 349 | + res.pipe(concat(function(body) { |
| 350 | + expect(body.toString('utf8')).eql('my-custom-response'); |
| 351 | + source.close(); |
| 352 | + proxyServer.close(); |
| 353 | + done(); |
| 354 | + })); |
| 355 | + }).once('error', done); |
| 356 | + }) |
| 357 | + }); |
| 358 | + |
319 | 359 | it('should proxy the request and handle changeOrigin option', function (done) { |
320 | 360 | var proxy = httpProxy.createProxyServer({ |
321 | 361 | target: 'http://127.0.0.1:8080', |
|
0 commit comments