@@ -26,15 +26,19 @@ async def test_proxy_fix_legacy() -> None:
26
26
(b"x-forwarded-for" , b"127.0.0.1" ),
27
27
(b"x-forwarded-for" , b"127.0.0.2" ),
28
28
(b"x-forwarded-proto" , b"http,https" ),
29
+ (b"x-forwarded-host" , b"example.com" ),
29
30
],
30
31
"client" : ("127.0.0.3" , 80 ),
31
32
"server" : None ,
32
33
"extensions" : {},
33
34
}
34
35
await app (scope , None , None )
35
36
mock .assert_called ()
36
- assert mock .call_args [0 ][0 ]["client" ] == ("127.0.0.2" , 0 )
37
- assert mock .call_args [0 ][0 ]["scheme" ] == "https"
37
+ scope = mock .call_args [0 ][0 ]
38
+ assert scope ["client" ] == ("127.0.0.2" , 0 )
39
+ assert scope ["scheme" ] == "https"
40
+ host_headers = [h for h in scope ["headers" ] if h [0 ].lower () == b"host" ]
41
+ assert host_headers == [(b"host" , b"example.com" )]
38
42
39
43
40
44
@pytest .mark .asyncio
@@ -52,13 +56,16 @@ async def test_proxy_fix_modern() -> None:
52
56
"query_string" : b"" ,
53
57
"root_path" : "" ,
54
58
"headers" : [
55
- (b"forwarded" , b"for=127.0.0.1;proto=http,for=127.0.0.2;proto=https" ),
59
+ (b"forwarded" , b"for=127.0.0.1;proto=http,for=127.0.0.2;proto=https;host=example.com " ),
56
60
],
57
61
"client" : ("127.0.0.3" , 80 ),
58
62
"server" : None ,
59
63
"extensions" : {},
60
64
}
61
65
await app (scope , None , None )
62
66
mock .assert_called ()
63
- assert mock .call_args [0 ][0 ]["client" ] == ("127.0.0.2" , 0 )
64
- assert mock .call_args [0 ][0 ]["scheme" ] == "https"
67
+ scope = mock .call_args [0 ][0 ]
68
+ assert scope ["client" ] == ("127.0.0.2" , 0 )
69
+ assert scope ["scheme" ] == "https"
70
+ host_headers = [h for h in scope ["headers" ] if h [0 ].lower () == b"host" ]
71
+ assert host_headers == [(b"host" , b"example.com" )]
0 commit comments