File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
src/Illuminate/Http/Middleware Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public function handle($request, $next)
2121 if ($ response instanceof Response && Vite::preloadedAssets () !== []) {
2222 $ response ->header ('Link ' , Collection::make (Vite::preloadedAssets ())
2323 ->map (fn ($ attributes , $ url ) => "< {$ url }>; " .implode ('; ' , $ attributes ))
24- ->join (', ' ));
24+ ->join (', ' ), false );
2525 }
2626 });
2727 }
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ public function testItAddsPreloadLinkHeader()
5454 });
5555
5656 $ this ->assertSame (
57+ '<https://laravel.com/app.js>; rel="modulepreload"; foo="bar" ' ,
5758 $ response ->headers ->get ('Link ' ),
58- '<https://laravel.com/app.js>; rel="modulepreload"; foo="bar" '
5959 );
6060 }
6161
@@ -79,4 +79,31 @@ public function testItDoesNotAttachHeadersToNonIlluminateResponses()
7979
8080 $ this ->assertNull ($ response ->headers ->get ('Link ' ));
8181 }
82+
83+ public function testItDoesNotOverwriteOtherLinkHeaders ()
84+ {
85+ $ app = new Container ;
86+ $ app ->instance (Vite::class, new class extends Vite
87+ {
88+ protected $ preloadedAssets = [
89+ 'https://laravel.com/app.js ' => [
90+ 'rel="modulepreload" ' ,
91+ 'foo="bar" ' ,
92+ ],
93+ ];
94+ });
95+ Facade::setFacadeApplication ($ app );
96+
97+ $ response = (new AddLinkHeadersForPreloadedAssets )->handle (new Request , function () {
98+ return new Response ('Hello Laravel ' , headers: ['Link ' => '<https://laravel.com/logo.png>; rel="preload"; as="image" ' ]);
99+ });
100+
101+ $ this ->assertSame (
102+ [
103+ '<https://laravel.com/logo.png>; rel="preload"; as="image" ' ,
104+ '<https://laravel.com/app.js>; rel="modulepreload"; foo="bar" ' ,
105+ ],
106+ $ response ->headers ->all ('Link ' ),
107+ );
108+ }
82109}
You can’t perform that action at this time.
0 commit comments