@@ -4,38 +4,45 @@ var assert = require('assert');
4
4
var express = require ( 'express' ) ;
5
5
var request = require ( 'supertest' ) ;
6
6
var proxy = require ( '../' ) ;
7
+ var http = require ( 'http' ) ;
7
8
8
9
describe ( 'userResDecorator' , function ( ) {
9
10
10
- describe ( 'when handling a 304 ' , function ( ) {
11
+ describe ( 'when handling no body ' , function ( ) {
11
12
this . timeout ( 10000 ) ;
12
13
13
14
var app ;
14
- var slowTarget ;
15
- var serverReference ;
15
+ var noBodyTarget ;
16
+ var serverReference ;
17
+ var responseCode ;
16
18
17
19
beforeEach ( function ( ) {
18
20
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 ) ;
22
27
} ) ;
23
28
24
29
afterEach ( function ( ) {
25
30
serverReference . close ( ) ;
26
31
} ) ;
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 ' + status + ' with no body' ) ;
38
+ }
39
+ } ) ) ;
40
+
41
+ request ( app )
42
+ . get ( '/proxy' )
43
+ . expect ( status )
44
+ . end ( done ) ;
45
+ } ) ;
39
46
} ) ;
40
47
} ) ;
41
48
0 commit comments