KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
url.h File Reference
#include <stddef.h>
Include dependency graph for url.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlUrl
 Parsed URL components (points into original URL string). More...
 

Macros

#define KL_URL_MAX   2048
 Maximum URL length for resolved URLs.
 

Functions

int kl_url_parse (const char *url, KlUrl *out)
 Parse an HTTP/HTTPS URL into components.
 
int kl_url_resolve (const char *base_url, const char *location, char *out, size_t out_size)
 Resolve a Location header value against a base URL.
 

Macro Definition Documentation

◆ KL_URL_MAX

#define KL_URL_MAX   2048

Maximum URL length for resolved URLs.

Function Documentation

◆ kl_url_parse()

int kl_url_parse ( const char *  url,
KlUrl out 
)

Parse an HTTP/HTTPS URL into components.

Supports http://, https://, ws://, and wss:// schemes, IPv6 addresses in brackets ([::1]:port), explicit ports, and path+query. Rejects CRLF injection in hostname and path.

Parameters
urlURL string to parse.
outParsed components (pointers into url).
Returns
0 on success, -1 on error.

◆ kl_url_resolve()

int kl_url_resolve ( const char *  base_url,
const char *  location,
char *  out,
size_t  out_size 
)

Resolve a Location header value against a base URL.

Handles absolute URLs (http:// or https://), protocol-relative (//), and absolute-path (/...) references. Strips fragment (#) if present. Bare relative refs (../foo) are not supported and return -1.

Parameters
base_urlThe URL of the current request.
locationThe Location header value.
outOutput buffer for the resolved URL.
out_sizeSize of the output buffer.
Returns
0 on success, -1 on error.