-
Notifications
You must be signed in to change notification settings - Fork 14
Configure request headers used in cache keys #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 9 commits
a140b8a
bf3dfe4
a205f96
40c6544
29c7ecb
6c8fd10
4981d3f
dafd919
a1c7e51
bb1a106
44f1b25
1738a00
b94db2f
1cde10a
52bc96e
be07ab9
9ae5731
78741db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace RemoteDataBlocks\HttpClient; | ||
|
|
||
| final class CacheKeyRequestHeaders { | ||
| public const DEFAULT_HEADERS = [ 'Authorization', 'Cache-Control' ]; | ||
|
|
||
| /** | ||
| * Merge request header name lists without case-insensitive duplicates. | ||
| * | ||
| * @param array<string> ...$header_lists Request header name lists. | ||
| * @return array<string> Merged request header names. | ||
| */ | ||
| public static function merge( array ...$header_lists ): array { | ||
| $merged_headers = []; | ||
| $seen_headers = []; | ||
|
|
||
| foreach ( $header_lists as $header_list ) { | ||
| foreach ( $header_list as $header ) { | ||
| $normalized_header = strtolower( $header ); | ||
| if ( isset( $seen_headers[ $normalized_header ] ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $seen_headers[ $normalized_header ] = true; | ||
| $merged_headers[] = $header; | ||
| } | ||
| } | ||
|
|
||
| return $merged_headers; | ||
|
maxschmeling marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,19 @@ | |
|
|
||
| namespace RemoteDataBlocks\HttpClient; | ||
|
|
||
| use Psr\Http\Message\RequestInterface; | ||
|
|
||
| class RdbCacheMiddleware extends \Kevinrob\GuzzleCache\CacheMiddleware { | ||
| public const CACHE_KEY_REQUEST_HEADERS_HEADER = 'X-Remote-Data-Blocks-Cache-Key-Headers'; | ||
|
chriszarate marked this conversation as resolved.
Outdated
|
||
|
|
||
| public function __invoke( callable $handler ): callable { | ||
|
maxschmeling marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand what is accomplished by this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left over duplicate. I've removed it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, I don't think this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't. I removed it but didn't get that in the commit I guess. Pushed in 78741db |
||
| $handler_without_cache_metadata = function ( RequestInterface $request, array $options ) use ( $handler ) { | ||
| return $handler( $request->withoutHeader( self::CACHE_KEY_REQUEST_HEADERS_HEADER ), $options ); | ||
| }; | ||
|
|
||
| return parent::__invoke( $handler_without_cache_metadata ); | ||
| } | ||
|
|
||
| /** | ||
| * @var array<string, true> | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.