@@ -112,6 +112,8 @@ class WSHandler {
112112 }
113113
114114 onUpgrade ( statusCode , headers , socket ) {
115+ // TODO: Check statusCode?
116+
115117 if ( this . head && this . head . length ) {
116118 socket . unshift ( this . head )
117119 }
@@ -125,17 +127,12 @@ class WSHandler {
125127 proxyName : this . proxyName ,
126128 httpVersion : this . httpVersion
127129 } )
130+
128131 for ( let n = 0 ; n < headers . length ; n += 2 ) {
129132 const key = headers [ n + 0 ]
130133 const val = headers [ n + 1 ]
131134
132- if ( ! Array . isArray ( val ) ) {
133- head += `\r\n${ key } : ${ val } `
134- } else {
135- for ( let i = 0 ; i < val . length ; i ++ ) {
136- head += `\r\n${ key } : ${ val [ i ] } `
137- }
138- }
135+ head += `\r\n${ key } : ${ val } `
139136 }
140137 head += '\r\n\r\n'
141138
@@ -213,11 +210,12 @@ function getHeaders ({
213210 `proto=${ socket . encrypted ? 'https' : 'http' } ` ,
214211 `host=${ printIp ( authority || host || '' ) } `
215212 ] . join ( ';' ) )
216- } else {
217- result . push ( 'forwarded' , forwarded )
213+ } else if ( forwarded ) {
214+ // The forwarded header should not be included in response.
215+ throw new createError . BadGateway ( )
218216 }
219217
220- if ( httpVersion && proxyName ) {
218+ if ( proxyName ) {
221219 if ( via ) {
222220 if ( via . split ( ',' ) . some ( name => name . endsWith ( proxyName ) ) ) {
223221 throw new createError . LoopDetected ( )
0 commit comments