@@ -22,22 +22,20 @@ describe('lib/caronte/streams/proxy.js', function () {
22
22
} ) ;
23
23
} ) ;
24
24
25
- describe ( 'should pipe the request and finish it ' , function ( ) {
25
+ describe ( 'caronte createProxyServer() method ' , function ( ) {
26
26
it ( 'should make the request on pipe and finish it' , function ( done ) {
27
- var result ;
28
-
29
- var p = caronte . createProxyServer ( {
27
+ var proxy = caronte . createProxyServer ( {
30
28
target : 'http://127.0.0.1:8080'
31
29
} ) . listen ( '8081' ) ;
32
30
33
- var s = http . createServer ( function ( req , res ) {
31
+ var source = http . createServer ( function ( req , res ) {
34
32
expect ( req . headers [ 'x-forwarded-for' ] ) . to . eql ( '127.0.0.1' ) ;
35
- s . close ( ) ;
36
- p . close ( ) ;
33
+ source . close ( ) ;
34
+ proxy . close ( ) ;
37
35
done ( ) ;
38
36
} ) ;
39
37
40
- s . listen ( '8080' ) ;
38
+ source . listen ( '8080' ) ;
41
39
42
40
http . request ( {
43
41
hostname : '127.0.0.1' ,
@@ -49,4 +47,38 @@ describe('lib/caronte/streams/proxy.js', function () {
49
47
} , function ( ) { } ) . end ( ) ;
50
48
} ) ;
51
49
} ) ;
50
+
51
+ describe ( 'caronte createProxyServer() method with response' , function ( ) {
52
+ it ( 'should make the request, handle response and finish it' , function ( done ) {
53
+ var proxy = caronte . createProxyServer ( {
54
+ target : 'http://127.0.0.1:8080'
55
+ } ) . listen ( '8081' ) ;
56
+
57
+ var source = http . createServer ( function ( req , res ) {
58
+ expect ( req . method ) . to . eql ( 'GET' ) ;
59
+ res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } )
60
+ res . end ( 'Hello from ' + source . address ( ) . port ) ;
61
+ } ) ;
62
+
63
+ source . listen ( '8080' ) ;
64
+
65
+ http . request ( {
66
+ hostname : '127.0.0.1' ,
67
+ port : '8081' ,
68
+ method : 'GET' ,
69
+ } , function ( res ) {
70
+ expect ( res . statusCode ) . to . eql ( 200 ) ;
71
+
72
+ res . on ( 'data' , function ( data ) {
73
+ expect ( data . toString ( ) ) . to . eql ( 'Hello from 8080' ) ;
74
+ } ) ;
75
+
76
+ res . on ( 'end' , function ( ) {
77
+ source . close ( ) ;
78
+ proxy . close ( ) ;
79
+ done ( ) ;
80
+ } ) ;
81
+ } ) . end ( ) ;
82
+ } ) ;
83
+ } ) ;
52
84
} ) ;
0 commit comments