@@ -4,38 +4,46 @@ var assert = require('assert');
44var express = require ( 'express' ) ;
55var request = require ( 'supertest' ) ;
66var proxy = require ( '../' ) ;
7+ var http = require ( 'http' ) ;
78
89describe ( 'userResDecorator' , function ( ) {
910
10- describe ( 'when handling a 304 ' , function ( ) {
11+ describe ( 'when handling no body ' , function ( ) {
1112 this . timeout ( 10000 ) ;
1213
1314 var app ;
14- var slowTarget ;
15- var serverReference ;
15+ var noBodyTarget ;
16+ var serverReference ;
17+ var responseCode ;
1618
1719 beforeEach ( function ( ) {
1820 app = express ( ) ;
19- slowTarget = express ( ) ;
20- slowTarget . use ( function ( req , res ) { res . sendStatus ( 304 ) ; } ) ;
21- serverReference = slowTarget . listen ( 12345 ) ;
21+ noBodyTarget = new http . Server ( ) ;
22+ noBodyTarget . on ( 'request' , function ( req , res ) {
23+ res . writeHead ( responseCode , { 'Content-Length' : '0' } ) ;
24+ res . end ( ) ;
25+ } ) ;
26+ serverReference = noBodyTarget . listen ( 12345 ) ;
2227 } ) ;
2328
2429 afterEach ( function ( ) {
2530 serverReference . close ( ) ;
2631 } ) ;
27-
28- it ( 'skips any handling' , function ( done ) {
29- app . use ( '/proxy' , proxy ( 'http://127.0.0.1:12345' , {
30- userResDecorator : function ( /*res*/ ) {
31- throw new Error ( 'expected to never get here because this step should be skipped for 304' ) ;
32- }
33- } ) ) ;
34-
35- request ( app )
36- . get ( '/proxy' )
37- . expect ( 304 )
38- . end ( done ) ;
32+ [ 200 , 201 , 204 , 205 , 301 , 302 , 304 , 400 , 500 ] . forEach ( function ( status ) {
33+ it ( 'skips any handling for ' + status , function ( done ) {
34+ responseCode = status ;
35+ app . use ( '/proxy' , proxy ( 'http://127.0.0.1:12345' , {
36+ userResDecorator : function ( /*res*/ ) {
37+ throw new Error ( 'expected to never get here because this step should be skipped for ' +
38+ status + ' with no body' ) ;
39+ }
40+ } ) ) ;
41+
42+ request ( app )
43+ . get ( '/proxy' )
44+ . expect ( status )
45+ . end ( done ) ;
46+ } ) ;
3947 } ) ;
4048 } ) ;
4149
0 commit comments