1616use Symfony \Component \HttpFoundation \Session \SessionInterface ;
1717use Symfony \Component \Routing \Exception \MethodNotAllowedException ;
1818use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
19+ use Symfony \Component \Routing \Generator \UrlGenerator ;
1920use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
2021use Symfony \Component \Routing \Matcher \RequestMatcherInterface ;
2122use Symfony \Component \Routing \Matcher \UrlMatcherInterface ;
2223use Symfony \Component \Routing \RequestContext ;
24+ use Symfony \Component \Routing \Route ;
25+ use Symfony \Component \Routing \RouteCollection ;
2326use Symfony \Component \Security \Http \HttpUtils ;
2427use Symfony \Component \Security \Http \SecurityRequestAttributes ;
2528
@@ -233,7 +236,7 @@ public static function provideSecurityRequestAttributes()
233236 ];
234237 }
235238
236- public function testCreateRequestHandlesTrustedHeaders ()
239+ public function testCreateRequestFromPathHandlesTrustedHeaders ()
237240 {
238241 Request::setTrustedProxies (['127.0.0.1 ' ], Request::HEADER_X_FORWARDED_PREFIX );
239242
@@ -243,6 +246,24 @@ public function testCreateRequestHandlesTrustedHeaders()
243246 );
244247 }
245248
249+ public function testCreateRequestFromRouteHandlesTrustedHeaders ()
250+ {
251+ Request::setTrustedProxies (['127.0.0.1 ' ], Request::HEADER_X_FORWARDED_PREFIX );
252+
253+ $ request = Request::create ('/ ' , server: ['HTTP_X_FORWARDED_PREFIX ' => '/foo ' ]);
254+
255+ $ urlGenerator = new UrlGenerator (
256+ $ routeCollection = new RouteCollection (),
257+ (new RequestContext ())->fromRequest ($ request ),
258+ );
259+ $ routeCollection ->add ('root ' , new Route ('/ ' ));
260+
261+ $ this ->assertSame (
262+ 'http://localhost/foo/ ' ,
263+ (new HttpUtils ($ urlGenerator ))->createRequest ($ request , 'root ' )->getUri (),
264+ );
265+ }
266+
246267 public function testCheckRequestPath ()
247268 {
248269 $ utils = new HttpUtils ($ this ->getUrlGenerator ());
0 commit comments