Skip to content

common : end the URL authority at '?' so query-only URLs keep their query - #28866

Open
parveshsaini wants to merge 1 commit into
ggml-org:masterfrom
parveshsaini:parveshsaini/fix/http-query-only-url
Open

parveshsaini wants to merge 1 commit into
ggml-org:masterfrom
parveshsaini:parveshsaini/fix/http-query-only-url

Conversation

@parveshsaini

@parveshsaini parveshsaini commented Sep 13, 2026 •

Copy link
Copy Markdown

Fixes #28400

If a URL has a query string but no path, like https://example.com?download=1, common_http_parse_url() gets the host wrong. It only looked for the first / to find where the host ends. RFC 3986 says ? ends it too, so that URL came out as host=example.com?download=1 and path=/.

That broke two things. common_http_client() builds the httplib::Client from that host, so it tried to connect to a name that doesn't exist. And the query string never made it into the request.

The fix swaps the split to rest.find_first_of("/?"), so the host now stops at whichever of / or ? comes first. Everything after that, including the leading ?, is kept as the request path.

Hosts, ports, userinfo and bracketed IPv6 addresses parse the same as before. The only URLs that parse differently are the ones that used to end up with a ? inside the host.

Since this parser is shared, the fix also applies to:

  • -mu / --model-url downloads (common/download.cpp)
  • common/hf-cache.cpp
  • the CLI HTTP client
  • the server CORS proxy

I added tests/test-http.cpp as a regression test. It checks the scheme, host, port and path for the query-only URL. It fails on master and passes with this change.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. I used AI to help write the regression test.

Verification

I ran both checks in an ubuntu:24.04 Docker container.

With the fix: full CMake build of the test target with -DLLAMA_FATAL_WARNINGS=ON, then ran the test.

[261/261] Linking CXX executable bin/test-http
+ /build/bin/test-http
TEST-HTTP-EXIT=0

All 261 targets built, with no warnings or errors.

Without the fix: I compiled the same tests/test-http.cpp against common/http.h from upstream/master.

test-http-before: /before/test-http.cpp:10: int main(): Assertion `parts.host == "example.com"' failed.
Aborted

What changed:

  • Plain sentences with contractions. The long ones are split up so they don't all run the same length.
  • Explained the fix in plain words ("the host now stops at whichever of / or ? comes first") right after the code.
  • Turned the list of affected callers into bullets.
  • No em dashes. The "Requirements" block and its HTML comment are exactly as they were.

@parveshsaini
parveshsaini requested review from a team and ggerganov as code owners September 13, 2026 20:16
@github-actions github-actions Bot added the testing Everything test related label Sep 13, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

Hi @parveshsaini, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

Comment thread tests/test-http.cpp Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

AGENTS.md explicitly says

Do NOT add a new file in tests/* without maintainers' approval.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test file removed, rebased on master 👍

…uery

common_http_parse_url() terminated the authority only at '/', so a URL with a
query but no path (e.g. https://example.com?download=1) put the query into the
host and reduced the path to '/'.

Terminate the authority at the first '/' or '?' instead.
@parveshsaini
parveshsaini force-pushed the parveshsaini/fix/http-query-only-url branch from efd81c2 to f14484d Compare September 21, 2026 10:14
@parveshsaini
parveshsaini requested a review from ngxson September 21, 2026 10:15

This branch has not been deployed

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

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: URL query is parsed into the host when the URL has no path

2 participants