@@ -53,22 +53,45 @@ describe('req.host', () => {
53
53
54
54
describe ( 'when X-Forwarded-Host is present' , ( ) => {
55
55
describe ( 'and proxy is not trusted' , ( ) => {
56
- it ( 'should be ignored' , ( ) => {
56
+ it ( 'should be ignored on HTTP/1 ' , ( ) => {
57
57
const req = request ( ) ;
58
58
req . header [ 'x-forwarded-host' ] = 'bar.com' ;
59
59
req . header . host = 'foo.com' ;
60
60
assert . equal ( req . host , 'foo.com' ) ;
61
61
} ) ;
62
+
63
+ it ( 'should be ignored on HTTP/2' , ( ) => {
64
+ const req = request ( {
65
+ 'httpVersionMajor' : 2 ,
66
+ 'httpVersion' : '2.0'
67
+ } ) ;
68
+ req . header [ 'x-forwarded-host' ] = 'proxy.com:8080' ;
69
+ req . header [ ':authority' ] = 'foo.com:3000' ;
70
+ req . header . host = 'bar.com:8000' ;
71
+ assert . equal ( req . host , 'foo.com:3000' ) ;
72
+ } ) ;
62
73
} ) ;
63
74
64
75
describe ( 'and proxy is trusted' , ( ) => {
65
- it ( 'should be used' , ( ) => {
76
+ it ( 'should be used on HTTP/1 ' , ( ) => {
66
77
const req = request ( ) ;
67
78
req . app . proxy = true ;
68
79
req . header [ 'x-forwarded-host' ] = 'bar.com, baz.com' ;
69
80
req . header . host = 'foo.com' ;
70
81
assert . equal ( req . host , 'bar.com' ) ;
71
82
} ) ;
83
+
84
+ it ( 'should be used on HTTP/2' , ( ) => {
85
+ const req = request ( {
86
+ 'httpVersionMajor' : 2 ,
87
+ 'httpVersion' : '2.0'
88
+ } ) ;
89
+ req . app . proxy = true ;
90
+ req . header [ 'x-forwarded-host' ] = 'proxy.com:8080' ;
91
+ req . header [ ':authority' ] = 'foo.com:3000' ;
92
+ req . header . host = 'bar.com:8000' ;
93
+ assert . equal ( req . host , 'proxy.com:8080' ) ;
94
+ } ) ;
72
95
} ) ;
73
96
} ) ;
74
97
} ) ;
0 commit comments