File tree 2 files changed +29
-2
lines changed
src/Illuminate/Http/Middleware
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)
21
21
if ($ response instanceof Response && Vite::preloadedAssets () !== []) {
22
22
$ response ->header ('Link ' , Collection::make (Vite::preloadedAssets ())
23
23
->map (fn ($ attributes , $ url ) => "< {$ url }>; " .implode ('; ' , $ attributes ))
24
- ->join (', ' ));
24
+ ->join (', ' ), false );
25
25
}
26
26
});
27
27
}
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ public function testItAddsPreloadLinkHeader()
54
54
});
55
55
56
56
$ this ->assertSame (
57
+ '<https://laravel.com/app.js>; rel="modulepreload"; foo="bar" ' ,
57
58
$ response ->headers ->get ('Link ' ),
58
- '<https://laravel.com/app.js>; rel="modulepreload"; foo="bar" '
59
59
);
60
60
}
61
61
@@ -79,4 +79,31 @@ public function testItDoesNotAttachHeadersToNonIlluminateResponses()
79
79
80
80
$ this ->assertNull ($ response ->headers ->get ('Link ' ));
81
81
}
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
+ }
82
109
}
You can’t perform that action at this time.
0 commit comments