diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index 486509abe7..68d4c03624 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -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, diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index 99a7906a69..93806ecf0b 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -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 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 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; } diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index fd22f1be68..d7deddcb76 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -149,6 +149,7 @@ sub authenticate_api_request { $c->stash_embed( { spec => $spec } ); $c->stash_overrides(); + $c->stash_request_id(); my $cookie_auth = 0;