Skip to content

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

Closed as not planned

Description

@parveshsaini

Name and Version

$ llama-server --version
version: 0.3.0-dev (build 10797, commit 235f4e8)

Operating systems

Linux

Which llama.cpp modules do you know to be affected?

llama-cli, llama-server, libllama (core library)

Command line

llama-cli -mu 'https://example.com/model.gguf?download=1'

Problem description & steps to reproduce

Description

common_http_parse_url() in common/http.h splits the authority from the path by searching for the first /:

auto slash_pos = rest.find('/');

RFC 3986 ends the authority at the first /, ? or #, so a URL that carries a query but no path never terminates the authority. For https://example.com?download=1 the parser produces:

host -> example.com?download=1
path -> /

Two things then go wrong in common_http_client(), which builds the httplib::Client out of parts.host: the connection is attempted against a hostname that cannot resolve, and the query string is dropped from the request even if it could.

This parser is shared, so the same failure reaches every HTTP caller in the tree:
common/download.cpp (-mu / --model-url and remote GGUF fetches), common/hf-cache.cpp,
tools/cli/cli-client.cpp, and the server CORS proxy in tools/server/server-cors-proxy.h.

Query-only URLs are ordinary and commonly machine-generated, signed download links, CDN cache-busting parameters, and ?download=1-style flags, so this is hit by real endpoints rather than only by malformed input.


Repro

#include "common/http.h"
#include <iostream>

int main() {
    const auto parts = common_http_parse_url("https://example.com?download=1");
    std::cout << "host=" << parts.host << " path=" << parts.path << '\n';
}
g++ -std=c++17 -I. -Ivendor -Ivendor/cpp-httplib repro.cpp vendor/cpp-httplib/httplib.cpp -pthread -o repro
./repro

First Bad Commit

The find('/') split has been present since common/http.h was introduced in #16373;

Relevant log output

Logs
expected host=example.com path=?download=1
actual host=example.com?download=1 path=/

Activity

  1. parveshsaini commented on Sep 4, 2026

    @parveshsaini
    Author

    Suggested fix:
    End the authority at the first / or ? (rest.find_first_of("/?")) and keep the remainder, leading ? included, as the request path, which is what httplib expects. A # fragment could be handled the same way, though it is not part of what is sent on the wire.

    Happy to pick this up and raise a quick PR 🚀

  2. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions