Bug 40423: Add helper to stash x-koha-request-id header value
This patch aligns handling of the header with how other headers are
managed.
* A helper is added which reads the header and stashes the value
* The helper is called in the same place similar helpers are called
(authenticate_api_request)
* The `objects.search_rs` helper is adjusted to use the stashed value
instead of picking it from the reserved params.
To test:
1. Apply this patches
2. Run:
$ ktd --shell
k$ prove t/Koha/REST/Plugin/Query.t \
t/db_dependent/api/v1/*.t \
t/db_dependent/Koha/REST/Plugin/*
=> SUCCESS: Tests pass! No behavior change!
3. Sign off :-D
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5e94e44ee2)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
87b3ef3c31
commit
5eb0968866
|
|
@ -263,8 +263,8 @@ controller, and thus shouldn't be called twice in it.
|
|||
}
|
||||
|
||||
# request sequence id (i.e. 'draw' Datatables parameter)
|
||||
$c->res->headers->add( 'x-koha-request-id' => $reserved_params->{'x-koha-request-id'} )
|
||||
if $reserved_params->{'x-koha-request-id'};
|
||||
$c->res->headers->add( 'x-koha-request-id' => $c->stash('koha.request_id') )
|
||||
if $c->stash('koha.request_id');
|
||||
|
||||
# If search_limited exists, use it
|
||||
$result_set = $result_set->search_limited,
|
||||
|
|
|
|||
|
|
@ -284,12 +284,12 @@ Unwraps and stashes the x-koha-embed headers for use later query construction
|
|||
|
||||
# Stash the overrides
|
||||
$c->stash_overrides();
|
||||
#Use it
|
||||
# Use it
|
||||
my $overrides = $c->stash('koha.overrides');
|
||||
if ( $overrides->{pickup_location} ) { ... }
|
||||
|
||||
This helper method parses 'x-koha-override' headers and stashes the passed overriders
|
||||
in the for of a I<hashref> for easy use in controller methods.
|
||||
This helper method parses the 'x-koha-override' headers and stashes the passed overrides
|
||||
in the form of a I<hashref> for easy use in controller methods.
|
||||
|
||||
FIXME: With the currently used JSON::Validator version we use, it is not possible to
|
||||
use the validated and coerced data (it doesn't validate array-type headers) so this
|
||||
|
|
@ -309,6 +309,30 @@ reference: https://metacpan.org/changes/distribution/JSON-Validator#L14
|
|||
|
||||
$c->stash( 'koha.overrides' => $overrides );
|
||||
|
||||
return $c;
|
||||
}
|
||||
);
|
||||
|
||||
=head3 stash_request_id
|
||||
|
||||
# Stash the request ID
|
||||
$c->stash_request_id();
|
||||
# Use it
|
||||
my $request_id = $c->stash('koha.request_id');
|
||||
|
||||
This helper method parses the 'x-koha-request-id' header and stashes the value.
|
||||
|
||||
=cut
|
||||
|
||||
$app->helper(
|
||||
'stash_request_id' => sub {
|
||||
|
||||
my ($c) = @_;
|
||||
|
||||
my $request_id = $c->req->headers->header('x-koha-request-id') || q{};
|
||||
|
||||
$c->stash( 'koha.request_id' => $request_id );
|
||||
|
||||
return $c;
|
||||
}
|
||||
);
|
||||
|
|
@ -324,7 +348,7 @@ reference: https://metacpan.org/changes/distribution/JSON-Validator#L14
|
|||
|
||||
sub _reserved_words {
|
||||
|
||||
my @reserved_words = qw( _match _order_by _order_by[] _page _per_page q query x-koha-request-id x-koha-embed);
|
||||
my @reserved_words = qw( _match _order_by _order_by[] _page _per_page q query);
|
||||
return \@reserved_words;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ sub authenticate_api_request {
|
|||
|
||||
$c->stash_embed( { spec => $spec } );
|
||||
$c->stash_overrides();
|
||||
$c->stash_request_id();
|
||||
|
||||
my $cookie_auth = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue