Implementation:Ggml org Llama cpp Http Header
| Knowledge Sources | |
|---|---|
| Domains | Networking, HTTP |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Provides HTTP URL parsing and client creation utilities wrapping the cpp-httplib library.
Description
The `common_http_parse_url` function splits a URL string into scheme, user, password, host, and path components, validating that the scheme is http or https. The `common_http_client` function creates a configured `httplib::Client` from a URL, setting up basic authentication if credentials are present and enabling redirect following. The `common_http_show_masked_url` function produces a display-safe URL string with credentials replaced by asterisks. A compile-time check for `CPPHTTPLIB_OPENSSL_SUPPORT` throws an informative error if HTTPS is used without SSL support.
Usage
Use this header when making HTTP requests in the download module or server components. It abstracts HTTP client creation details and provides secure URL display for logging.
Code Reference
Source Location
- Repository: Ggml_org_Llama_cpp
- File: common/http.h
- Lines: 1-84
Signature
struct common_http_url {
std::string scheme;
std::string user;
std::string password;
std::string host;
std::string path;
};
static common_http_url common_http_parse_url(const std::string & url);
static std::pair<httplib::Client, common_http_url> common_http_client(const std::string & url);
static std::string common_http_show_masked_url(const common_http_url & parts);
Import
#include "http.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| url | const std::string & | Yes | Full URL string to parse (e.g., "https://user:pass@host.com/path") |
| parts | const common_http_url & | Yes | Parsed URL components for masked display |
Outputs
| Name | Type | Description |
|---|---|---|
| parse_url return | common_http_url | Struct with scheme, user, password, host, and path fields |
| http_client return | std::pair<httplib::Client, common_http_url> | Configured HTTP client and parsed URL components |
| show_masked_url return | std::string | URL string with credentials replaced by asterisks |
Usage Examples
#include "http.h"
// Parse a URL
auto parts = common_http_parse_url("https://user:pass@example.com/models/file.gguf");
// parts.scheme = "https", parts.user = "user", parts.host = "example.com"
// Create an HTTP client
auto [client, url_parts] = common_http_client("https://example.com/api/v1");
// client is ready for requests with redirect following enabled
// Display masked URL for logging
std::string safe_url = common_http_show_masked_url(url_parts);
// "https://****:****@example.com/api/v1"