Bug 40642

Summary: Koha::OAI::Server::Repository self_url incorrect when using Plack
Product: Koha Reporter: David Cook <dcook>
Component: Web servicesAssignee: Bugs List <koha-bugs>
Status: CONFIRMED --- QA Contact: Testopia <testopia>
Severity: minor    
Priority: P5 - low    
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description David Cook 2025-08-13 03:20:12 UTC
Koha's OAI-PMH server returns the "request URL" in a "request" element. 

If a requestURL isn't provided as an argument to a response, CGI::self_url() is used.

In Koha, we often use $repository->self_url(), but self_url isn't a method in the $repository object or its parent classes. Rather, CGI::self_url is imported into Koha::OAI::Server::Repository and via Perl automagic it acts like a method.

This is a problem for a number of reasons. Firstly, the path is incorrect. In KTD when using Plack, you wind up with a request URL like http://localhost:8080/opac/oai.pl. 

If you have a reverse proxy and you're doing things like HTTPS offloading, you'll wind up with a HTTP instead of a HTTPS URL. Stuff like that.

This also affects the "baseURL" used in the Identify response.

--

We should have a method like "repo_url()" where we use OPACBaseURL and rewrite the path using something like the following:

s!^/opac!/cgi-bin/koha!
Comment 1 David Cook 2025-08-13 03:22:57 UTC
Note that I've been setting the requestURL in Koha::OAI::Server::Repository for many years locally, as I had some OAI-PMH consumer that needed it fixed. 

But there are other Koha/OAI/Server/* modules that need to be updated too. 

I'll need to do some refactoring of what I have to cover what I describe in the "Description", but it shouldn't be that hard.

Just need to get a round tuit...