parse_url()
#
Parses a given URL into its components, including schema, host, port, path, and query. Supports optional schema parsing.
Prototype
int parse_url(
hgobj gobj,
const char *uri,
char *schema, size_t schema_size,
char *host, size_t host_size,
char *port, size_t port_size,
char *path, size_t path_size,
char *query, size_t query_size,
BOOL no_schema
);
Parameters
Key |
Type |
Description |
---|---|---|
|
|
Handle to the calling object, used for logging errors. |
|
|
The URL string to be parsed. |
|
|
Buffer to store the extracted schema (e.g., ‘http’). |
|
|
Size of the schema buffer. |
|
|
Buffer to store the extracted host (e.g., ‘example.com’). |
|
|
Size of the host buffer. |
|
|
Buffer to store the extracted port (e.g., ‘8080’). |
|
|
Size of the port buffer. |
|
|
Buffer to store the extracted path (e.g., ‘/index.html’). |
|
|
Size of the path buffer. |
|
|
Buffer to store the extracted query string (e.g., ‘id=123’). |
|
|
Size of the query buffer. |
|
|
If TRUE, the function does not parse the schema. |
Return Value
Returns 0 on success, or -1 if the URL cannot be parsed.
Notes
Uses http_parser_parse_url()
to extract URL components. If no_schema
is TRUE, the schema is ignored.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples