@@ -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+ {--header=* : Set custom header (e.g. "Authorization: Bearer your_token")}
4546 ' ;
4647
4748 protected $ description = 'Warms the static cache by visiting all URLs ' ;
@@ -167,8 +168,10 @@ 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 ('header ' ));
172+
173+ return $ this ->uris ()->map (function ($ uri ) use ($ headers ) {
174+ return new Request ('GET ' , $ uri , $ headers );
172175 })->all ();
173176 }
174177
@@ -374,4 +377,25 @@ protected function additionalUris(): Collection
374377
375378 return $ uris ->map (fn ($ uri ) => URL ::makeAbsolute ($ uri ));
376379 }
380+
381+ private function parseHeaders ($ headerOptions ): array
382+ {
383+ $ headers = [];
384+ if (empty ($ headerOptions )) {
385+ return $ headers ;
386+ }
387+ if (! is_array ($ headerOptions )) {
388+ $ headerOptions = [$ headerOptions ];
389+ }
390+ foreach ($ headerOptions as $ header ) {
391+ if (strpos ($ header , ': ' ) !== false ) {
392+ [$ key , $ value ] = explode (': ' , $ header , 2 );
393+ $ headers [trim ($ key )] = trim ($ value );
394+ } else {
395+ $ this ->line ("<fg=yellow;options=bold>Warning:</> Invalid header format: ' $ header'. Headers should be in 'Key: Value' format. " );
396+ }
397+ }
398+
399+ return $ headers ;
400+ }
377401}
0 commit comments