OSSL_HTTP_PARSE_URL(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… OSSL_HTTP_PARSE_URL πŸ’…

okay bestie, so this is the OSSL_HTTP_PARSE_URL(3ossl) page β€” it's the one about the http helper functions in OpenSSL, and honestly it's giving "small but mighty" energy. we've got proxy adaptation, url splitting, and one deprecated little guy hanging out in the corner. let's get into it ✨


🌸 NAME 🌸

OSSL_HTTP_adapt_proxy, OSSL_parse_url, OSSL_HTTP_parse_url, OCSP_parse_url β€” http utility functions. that's the whole squad, no cap 🫢


✨ SYNOPSIS ✨

#include <openssl/http.h>

const char *OSSL_HTTP_adapt_proxy(const char *proxy, const char *no_proxy,
                                  const char *server, int use_ssl);

int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost,
                   char **pport, int *pport_num,
                   char **ppath, char **pquery, char **pfrag);
int OSSL_HTTP_parse_url(const char *url,
                        int *pssl, char **puser, char **phost,
                        char **pport, int *pport_num,
                        char **ppath, char **pquery, char **pfrag);
πŸ’€ okay so heads up: the following functions have been deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” see openssl_user_macros(7) for that whole situation.
int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath,
                   int *pssl);

like, they still work, but they're kinda on read-only mode socially. πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

πŸŽ€ OSSL_HTTP_adapt_proxy

okay so OSSL_HTTP_adapt_proxy() takes an optional proxy hostname proxy and returns it transformed according to the optional no_proxy parameter, server, use_ssl, and whatever environment variable applies. the tea β˜•:

  • if proxy is NULL, take any default value from the "http_proxy" environment variable β€” or from "https_proxy" if use_ssl is nonzero.
  • if that still doesn't yield a proxy hostname, take any further default value from the "HTTP_PROXY" environment variable β€” or from "HTTPS_PROXY" if use_ssl is nonzero.
  • if no_proxy is NULL, take any default exclusion value from the "no_proxy" environment variable, or else from "NO_PROXY".

then it returns the determined proxy host β€” unless the exclusion value (which is a list of proxy hosts separated by "," and/or whitespace, iykyk) contains server. in that case it returns NULL, no proxy for you bestie πŸ’…

little detail that matters: when server is a string delimited by "[" and "]" β€” those are the ones used for IPv6 addresses β€” the enclosing "[" and "]" get stripped prior to comparison. like, we compare the inside, not the brackets. periodt.

🧚 OSSL_parse_url

OSSL_parse_url() parses its input string url as a URL of this exact form:

[scheme://][userinfo@]host[:port][/path][?query][#fragment]

and splits it up into scheme, userinfo, host, port, path, query, and fragment components. iconique behavior honestly 🌈

  • the host (or server) component may be a DNS name or an IP address, and IPv6 addresses must be enclosed in square brackets "[" and "]".
  • the port component is optional and defaults to 0. if given, it must be in decimal form.
  • if the pport_num argument is not NULL, the integer value of the port number is assigned to *pport_num on success ✨
  • the path component is also optional and defaults to "/".
  • each non-NULL result pointer argument pscheme, puser, phost, pport, ppath, pquery, and pfrag, is assigned the respective url component.
  • any IPv6 address in *phost is enclosed in "[" and "]".
  • on success, they are guaranteed to contain non-NULL string pointers, else NULL.
  • it is the responsibility of the caller to free them using OPENSSL_free(3). don't forget, bestie, that's on you 🫢
  • if pquery is NULL, any given query component is handled as part of the path.
  • a string returned via *ppath is guaranteed to begin with a "/" character.
  • for absent scheme, userinfo, port, query, and fragment components, an empty string is provided.

πŸ“ OSSL_HTTP_parse_url

OSSL_HTTP_parse_url() is a special form of OSSL_parse_url() where the scheme, if given, must be "http" or "https". taste only πŸ‘‘

  • if pssl is not NULL, *pssl is assigned 1 in case parsing was successful and the scheme is "https", else 0.
  • the port component is optional and defaults to 443 if the scheme is "https", else 80.
  • ⚠️ note that relative paths must be given with a leading "/" β€” otherwise the first path element is interpreted as the host. yes, really. this is the trap. don't fall in it 😭

πŸ’€ OCSP_parse_url (the deprecated one)

calling the deprecated function OCSP_parse_url(url, host, port, path, ssl) is exactly equivalent to:

OSSL_HTTP_parse_url(url, ssl, NULL, host, port, NULL, path, NULL, NULL)

same energy, different packaging. it's giving legacy πŸŽ€


πŸ”₯ RETURN VALUES πŸ”₯

  • OSSL_HTTP_adapt_proxy() returns NULL if no proxy is to be used β€” otherwise a constant proxy hostname string, which is either the proxy name handed in or an environment variable value.
  • OSSL_parse_url(), OSSL_HTTP_parse_url(), and OCSP_parse_url() return 1 on success, 0 on error.

simple as that. one or zero. slay ✨


🌈 SEE ALSO 🌈

OSSL_HTTP_transfer(3) β€” go read that one too, bestie, it's the main character πŸ’–


⭐ HISTORY ⭐

OSSL_HTTP_adapt_proxy(), OSSL_parse_url() and OSSL_HTTP_parse_url() were added in OpenSSL 3.0. OCSP_parse_url() was deprecated in OpenSSL 3.0. so yeah, same release, different destinies 😭


Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


aaaaand that's the whole page 🫢 written by the OpenSSL fam, version 3.5.6, dated 2026-04-07 β€” mwah, thanks for reading, ily, go free your pointers πŸ’œπŸ¦‹

πŸ“¦ where this page comes from