Bugzilla – Attachment 184553 Details for
Bug 40423
Handling x-koha-request-id relies on wrong data structure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40423: Add helper to stash x-koha-request-id header value
Bug-40423-Add-helper-to-stash-x-koha-request-id-he.patch (text/plain), 4.16 KB, created by
Martin Renvoize (ashimema)
on 2025-07-23 14:20:54 UTC
(
hide
)
Description:
Bug 40423: Add helper to stash x-koha-request-id header value
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-07-23 14:20:54 UTC
Size:
4.16 KB
patch
obsolete
>From 0a80ff8c3d6bc8e22949a2b57af9692ea47c915e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 16 Jul 2025 23:31:58 -0300 >Subject: [PATCH] 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> >--- > Koha/REST/Plugin/Objects.pm | 4 ++-- > Koha/REST/Plugin/Query.pm | 32 ++++++++++++++++++++++++++++---- > Koha/REST/V1/Auth.pm | 1 + > 3 files changed, 31 insertions(+), 6 deletions(-) > >diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm >index 486509abe71..68d4c036243 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 99a7906a699..93806ecf0b0 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<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; > } > >diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm >index fd22f1be68c..d7deddcb76f 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; > >-- >2.50.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40423
:
184179
|
184180
|
184216
|
184217
|
184552
| 184553