Bugzilla – Attachment 177069 Details for
Bug 38929
POST endpoints not returning the Location header
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38929: Make POST endpoints return the `Location` header
Bug-38929-Make-POST-endpoints-return-the-Location-.patch (text/plain), 4.47 KB, created by
David Nind
on 2025-01-23 19:38:57 UTC
(
hide
)
Description:
Bug 38929: Make POST endpoints return the `Location` header
Filename:
MIME Type:
Creator:
David Nind
Created:
2025-01-23 19:38:57 UTC
Size:
4.47 KB
patch
obsolete
>From 66eaf3a014a883031652ee7220005dbecf13e352 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 20 Jan 2025 12:38:32 -0300 >Subject: [PATCH] Bug 38929: Make POST endpoints return the `Location` header > >This patch makes the POST endpoints missing the Location header return >it. > >Some endpoints I skipped: > >* /patrons/account/credits (doesn't have a GET route to point to) >* /patrons/account/debits (doesn't have a GET route to point to) > >To test: >1. Apply the regression tests >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/authorities.t \ > t/db_dependent/api/v1/biblios.t \ > t/db_dependent/api/v1/clubs_holds.t \ > t/db_dependent/api/v1/holds.t \ > t/db_dependent/api/v1/ill_batchstatuses.t \ > t/db_dependent/api/v1/import_batch_profiles.t \ > t/db_dependent/api/v1/transfer_limits.t >=> FAIL: Tests fail! The endpoints don't return the header! >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! >5. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/REST/V1/Biblios.pm | 6 ++++++ > Koha/REST/V1/Clubs/Holds.pm | 2 ++ > Koha/REST/V1/Holds.pm | 2 ++ > Koha/REST/V1/ILL/Batch/Statuses.pm | 1 + > Koha/REST/V1/ImportBatchProfiles.pm | 1 + > Koha/REST/V1/TransferLimits.pm | 2 ++ > 6 files changed, 14 insertions(+) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 010f96e7e9..21942b8f6e 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -370,6 +370,10 @@ sub add_item { > > $item->store->discard_changes; > >+ my $base_url = $c->req->url->to_string; >+ $base_url =~ s|/biblios/\d+||; >+ $c->res->headers->location( $base_url . '/' . $item->id ); >+ > $c->render( > status => 201, > openapi => $c->objects->to_api($item), >@@ -718,6 +722,8 @@ sub add { > ); > } > >+ $c->res->headers->location( $c->req->url->to_string . '/' . $biblio_id ); >+ > return $c->render( > status => 200, > openapi => { id => $biblio_id } >diff --git a/Koha/REST/V1/Clubs/Holds.pm b/Koha/REST/V1/Clubs/Holds.pm >index 851cc9358a..0643d4b7df 100644 >--- a/Koha/REST/V1/Clubs/Holds.pm >+++ b/Koha/REST/V1/Clubs/Holds.pm >@@ -108,6 +108,8 @@ sub add { > } > ); > >+ $c->res->headers->location( $c->req->url->to_string . '/' . $club_hold->id ); >+ > return $c->render( > status => 201, > openapi => $c->objects->to_api($club_hold), >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index 121e68313e..685a3697c1 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -216,6 +216,8 @@ sub add { > > my $hold = Koha::Holds->find($hold_id); > >+ $c->res->headers->location( $c->req->url->to_string . '/' . $hold_id ); >+ > return $c->render( > status => 201, > openapi => $c->objects->to_api($hold), >diff --git a/Koha/REST/V1/ILL/Batch/Statuses.pm b/Koha/REST/V1/ILL/Batch/Statuses.pm >index 45612f5f8d..ac22b0ca1c 100644 >--- a/Koha/REST/V1/ILL/Batch/Statuses.pm >+++ b/Koha/REST/V1/ILL/Batch/Statuses.pm >@@ -84,6 +84,7 @@ sub add { > openapi => $return > ); > } else { >+ $c->res->headers->location( $c->req->url->to_string . '/' . $status->code ); > return $c->render( > status => 201, > openapi => $status >diff --git a/Koha/REST/V1/ImportBatchProfiles.pm b/Koha/REST/V1/ImportBatchProfiles.pm >index c61b216690..51d43f4f0f 100644 >--- a/Koha/REST/V1/ImportBatchProfiles.pm >+++ b/Koha/REST/V1/ImportBatchProfiles.pm >@@ -68,6 +68,7 @@ sub add { > > return try { > my $profile = Koha::ImportBatchProfile->new_from_api( $body )->store; >+ $c->res->headers->location( $c->req->url->to_string . '/' . $profile->id ); > return $c->render( > status => 201, > openapi => $c->objects->to_api($profile), >diff --git a/Koha/REST/V1/TransferLimits.pm b/Koha/REST/V1/TransferLimits.pm >index 8e8515621f..50799a887e 100644 >--- a/Koha/REST/V1/TransferLimits.pm >+++ b/Koha/REST/V1/TransferLimits.pm >@@ -74,6 +74,8 @@ sub add { > Koha::Exceptions::TransferLimit::Duplicate->throw(); > } > >+ $c->res->headers->location( $c->req->url->to_string . '/' . $transfer_limit->id ); >+ > return $c->render( > status => 201, > openapi => $c->objects->to_api($transfer_limit), >-- >2.39.5
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 38929
:
176832
|
176833
|
176834
|
176901
|
176906
|
177068
|
177069
|
177070
|
177071
|
177072
|
177106
|
177107
|
177108
|
177109
|
177110