@@ -28,7 +28,6 @@ ProxyStream.prototype.onPipe = function(req) {
28
28
) ;
29
29
//console.log(common.setupOutgoing(self.options.ssl || {}, self.options, req));
30
30
this . proxyReq . once ( 'response' , function ( proxyRes ) {
31
- console . log ( proxyRes ) ;
32
31
self . onResponse ( proxyRes ) ;
33
32
} ) ;
34
33
this . proxyReq . on ( 'error' , function ( e ) {
@@ -43,46 +42,47 @@ ProxyStream.prototype.onFinish = function() {
43
42
ProxyStream . prototype . onResponse = function ( proxyRes ) {
44
43
this . proxyRes = proxyRes ;
45
44
46
- // rewrite
47
- if ( req . httpVersion === '1.0' ) {
48
- res . headers . connection = req . headers . connection || 'close' ;
49
- }
50
- else if ( ! res . headers . connection ) {
51
- res . headers . connection = req . headers . connection || 'keep-alive' ;
52
- }
53
-
54
- if ( req . httpVersion === '1.0' || ( req . method === 'DELETE' && ! req . headers [ 'content-length' ] ) ) {
55
- delete res . headers [ 'transfer-encoding' ] ;
56
- }
57
-
58
- if ( ~ [ 301 , 302 ] . indexOf ( res . statusCode ) && typeof res . headers . location !== 'undefined' ) {
59
- var location = url . parse ( res . headers . location ) ;
60
- if (
61
- location . host === req . headers . host &&
62
- (
63
- source . https && ! target . https ||
64
- target . https && ! source . https
65
- )
66
- ) {
67
- res . headers . location = res . headers . location . replace ( / ^ h t t p s \: / , 'http:' ) ;
68
- }
69
- }
70
-
71
- self . emit ( 'proxyResponse' , req , response , res ) ;
72
-
73
- Object . keys ( res . headers ) . forEach ( function ( key ) {
74
- response . setHeader ( key , res . headers [ key ] ) ;
75
- } ) ;
76
- response . writeHead ( response . statusCode ) ;
77
-
78
- res . on ( 'readable' , function ( ) {
79
- self . read ( 0 ) ;
80
- } ) ;
81
-
82
- res . on ( 'end' , function ( ) {
83
- self . push ( null ) ;
84
- } ) ;
85
- self . emit ( 'readable' ) ;
45
+ var self = this ;
46
+
47
+ if ( this . req . httpVersion === '1.0' ) {
48
+ proxyRes . headers . connection = this . req . headers . connection || 'close' ;
49
+ }
50
+ else if ( ! proxyRes . headers . connection ) {
51
+ proxyRes . headers . connection = this . req . headers . connection || 'keep-alive' ;
52
+ }
53
+
54
+ if ( this . req . httpVersion === '1.0' || ( this . req . method === 'DELETE' && ! this . req . headers [ 'content-length' ] ) ) {
55
+ delete proxyRes . headers [ 'transfer-encoding' ] ;
56
+ }
57
+
58
+ /*if(~[301,302].indexOf(this.res.statusCode) && typeof this.res.headers.location !== 'undefined') {
59
+ var location = url.parse(this.res.headers.location);
60
+ if (
61
+ location.host === this.req.headers.host &&
62
+ (
63
+ source.https && !target.https ||
64
+ target.https && !source.https
65
+ )
66
+ ) {
67
+ this.res.headers.location = this.res.headers.location.replace(/^https\:/, 'http:');
68
+ }
69
+ }*/
70
+
71
+ Object . keys ( proxyRes . headers ) . forEach ( function ( key ) {
72
+ self . res . setHeader ( key , proxyRes . headers [ key ] ) ;
73
+ } ) ;
74
+
75
+ this . res . writeHead ( proxyRes . statusCode ) ;
76
+
77
+ proxyRes . on ( 'readable' , function ( ) {
78
+ self . read ( 0 ) ;
79
+ } ) ;
80
+
81
+ proxyRes . on ( 'end' , function ( ) {
82
+ self . push ( null ) ;
83
+ } ) ;
84
+
85
+ self . emit ( 'readable' ) ;
86
86
} ;
87
87
88
88
ProxyStream . prototype . onError = function ( e ) {
0 commit comments