Skip to content

Fix lighttpd PATH_INFO extraction with MAPSERVER_BASE_PATH#1373

Open
Copilot wants to merge 1 commit intomasterfrom
copilot/add-test-case-for-issue-1108
Open

Fix lighttpd PATH_INFO extraction with MAPSERVER_BASE_PATH#1373
Copilot wants to merge 1 commit intomasterfrom
copilot/add-test-case-for-issue-1108

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 6, 2026

path_info.lua used Lua's gsub with a pattern built from MAPSERVER_BASE_PATH, which fails to correctly set request.path-info in lighttpd's mod_magnet environment — breaking mapfile alias resolution and ows_onlineresource construction in WMS GetCapabilities when the mapfile is specified as a path component.

Changes

  • runtime/etc/lighttpd/path_info.lua: Replace gsub-based extraction with plain-text find, as suggested in the upstream report:

    -- Before (broken)
    local result = path:gsub("^" .. base_path, "")
    lighty.r.req_attr["request.path-info"] = result
    
    -- After
    local base_i = path:find(base_path, 1, true)
    local base_l = base_path:len()
    if base_i == 1 and path:len() > base_l then
        lighty.r.req_attr["request.path-info"] = path:sub(base_l + 1)
    end

    find(..., 1, true) uses plain-text matching (no pattern interpretation), correctly stripping the base path and leaving the mapfile component as PATH_INFO.

  • acceptance_tests/test_wms.py: Add test_lighttpd_capabilities_url — verifies that GetMap operation URLs in the WMS GetCapabilities response start with BASE_URL_LIGHTTPD (i.e., include the correct base path + mapfile path), catching the PATH_INFO regression described in the issue.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add test case for issue 1108 comment Fix lighttpd PATH_INFO extraction with MAPSERVER_BASE_PATH Mar 6, 2026
@sbrunner sbrunner added the backport 8.6-gdal3.12 Add this label to backport the pull request to the '8.6-gdal3.12' branch label Mar 6, 2026
@sbrunner sbrunner marked this pull request as ready for review March 6, 2026 12:22
@sbrunner
Copy link
Copy Markdown
Member

sbrunner commented Mar 6, 2026

@johannes Does it looks good to you?

@johannes
Copy link
Copy Markdown

johannes commented Mar 6, 2026

I wouldn't use variable names base_i and base_l (i index, l length?)

But I am not the person you were looking for :)

Co-authored-by: sbrunner <353872+sbrunner@users.noreply.github.com>
@sbrunner sbrunner force-pushed the copilot/add-test-case-for-issue-1108 branch from 7e4d0e8 to 86a478c Compare March 6, 2026 15:04
@johanez
Copy link
Copy Markdown

johanez commented Mar 9, 2026

Thanks for the quick reaction @sbrunner .

Turns out I missed that mapserver uses lighty.r.req_attr["uri.path"] as SCRIPT_NAME, which together with PATH_INFO is used to dynamically construct the online-resource urls or GetCapabilties etc. if not defined in the mapfile.

So with my solution above, this duplicates the PATH_INFO part in the returned urls, e.g.: https://example.com/base_path/mapname/ogcapi/collections/mapname/ogcapi/collections/ in the output of https://example.com/base_path/mapname/ogcapi.

So one needs to remove the PATH_INFO path from lighty.r.req_attr["uri.path"]. (Which is discouraged, but seems to do no harm with mapserver).

So I end up with:

local base_path = os.getenv("MAPSERVER_BASE_PATH", "")
local path = lighty.r.req_attr["uri.path"]
local base_index = path:find(base_path, 1, true)
local base_length = base_path:len()

if base_index == 1 and path:len() > base_length  then
    lighty.r.req_attr["uri.path"] = base_path
    lighty.r.req_attr["request.path-info"] = path:sub(base_length + 1)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 8.6-gdal3.12 Add this label to backport the pull request to the '8.6-gdal3.12' branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants