@@ -116,6 +116,56 @@ describe('req', function(){
116
116
. set ( 'Host' , 'example.com' )
117
117
. expect ( 'example.com' , done ) ;
118
118
} )
119
+
120
+ describe ( 'when multiple X-Forwarded-Host' , function ( ) {
121
+ it ( 'should use the first value' , function ( done ) {
122
+ var app = express ( )
123
+
124
+ app . enable ( 'trust proxy' )
125
+
126
+ app . use ( function ( req , res ) {
127
+ res . send ( req . hostname )
128
+ } )
129
+
130
+ request ( app )
131
+ . get ( '/' )
132
+ . set ( 'Host' , 'localhost' )
133
+ . set ( 'X-Forwarded-Host' , 'example.com, foobar.com' )
134
+ . expect ( 200 , 'example.com' , done )
135
+ } )
136
+
137
+ it ( 'should remove OWS around comma' , function ( done ) {
138
+ var app = express ( )
139
+
140
+ app . enable ( 'trust proxy' )
141
+
142
+ app . use ( function ( req , res ) {
143
+ res . send ( req . hostname )
144
+ } )
145
+
146
+ request ( app )
147
+ . get ( '/' )
148
+ . set ( 'Host' , 'localhost' )
149
+ . set ( 'X-Forwarded-Host' , 'example.com , foobar.com' )
150
+ . expect ( 200 , 'example.com' , done )
151
+ } )
152
+
153
+ it ( 'should strip port number' , function ( done ) {
154
+ var app = express ( )
155
+
156
+ app . enable ( 'trust proxy' )
157
+
158
+ app . use ( function ( req , res ) {
159
+ res . send ( req . hostname )
160
+ } )
161
+
162
+ request ( app )
163
+ . get ( '/' )
164
+ . set ( 'Host' , 'localhost' )
165
+ . set ( 'X-Forwarded-Host' , 'example.com:8080 , foobar.com:8888' )
166
+ . expect ( 200 , 'example.com' , done )
167
+ } )
168
+ } )
119
169
} )
120
170
121
171
describe ( 'when "trust proxy" is disabled' , function ( ) {
0 commit comments