@@ -42,6 +42,7 @@ class StaticWarm extends Command
4242 {--include= : Only warm specific URLs}
4343 {--exclude= : Exclude specific URLs}
4444 {--max-requests= : Maximum number of requests to warm}
45+ {--headers= : Set custom headers (e.g. --headers="Authorization: Bearer your_token", can be used multiple times)}
4546 ' ;
4647
4748 protected $ description = 'Warms the static cache by visiting all URLs ' ;
@@ -167,8 +168,9 @@ private function getRelativeUri(int $index): string
167168
168169 private function requests ()
169170 {
170- return $ this ->uris ()->map (function ($ uri ) {
171- return new Request ('GET ' , $ uri );
171+ $ headers = $ this ->parseHeaders ($ this ->option ('headers ' ));
172+ return $ this ->uris ()->map (function ($ uri ) use ($ headers ) {
173+ return new Request ('GET ' , $ uri , $ headers );
172174 })->all ();
173175 }
174176
@@ -374,4 +376,24 @@ protected function additionalUris(): Collection
374376
375377 return $ uris ->map (fn ($ uri ) => URL ::makeAbsolute ($ uri ));
376378 }
379+
380+ private function parseHeaders ($ headerOptions ): array
381+ {
382+ $ headers = [];
383+ if (empty ($ headerOptions )) {
384+ return $ headers ;
385+ }
386+ if (!is_array ($ headerOptions )) {
387+ $ headerOptions = [$ headerOptions ];
388+ }
389+ foreach ($ headerOptions as $ header ) {
390+ if (strpos ($ header , ': ' ) !== false ) {
391+ [$ key , $ value ] = explode (': ' , $ header , 2 );
392+ $ headers [trim ($ key )] = trim ($ value );
393+ } else {
394+ $ this ->line ("<fg=yellow;options=bold>Warning:</> Invalid header format: ' $ header'. Headers should be in 'Key: Value' format. " );
395+ }
396+ }
397+ return $ headers ;
398+ }
377399}
0 commit comments