DataReelDataReelC++ Toolkit Documentation

URL Parser

gxsURL parses URLs into gxsURLInfo and encodes or decodes URL text.

Contents

Overview
Functions

Overview

Parse() splits scheme://user:passwd@host:port/path?query#fragment. IPv6 literal hosts are written in brackets ([2001:db8::1]:8443) and stored without them. When no port is given the scheme's default port is used (https 443, ftps 990, smtps 465, pop3s 995 and others).

gxsURLInfo u;
if(gxsURL::Parse("https://user:pw@[::1]:8443/data?id=5", u))
  std::cout << u.host << " " << u.port << " " << u.PathAndQuery() << "\n";

Functions

static bool gxsURL::Parse(std::string_view url, gxsURLInfo &u)

Parses an absolute URL. Returns false if it has no scheme or host or the port is not valid.

static int gxsURL::DefaultPort(std::string_view scheme)

Default port for a scheme, or 0.

static std::string gxsURL::Resolve(const gxsURLInfo &base, std::string_view location)

Turns a redirect location (absolute, /path or relative) into an absolute URL.

static std::string gxsURL::Encode(std::string_view s)

Percent-encodes everything except RFC 3986 unreserved characters.

static std::string gxsURL::Decode(std::string_view s, bool plus_is_space = false)

Decodes %XX sequences.

std::string gxsURLInfo::PathAndQuery() const

"/path?query", at least "/".

std::string gxsURLInfo::HostAndPort() const

Value for an HTTP Host header.

std::string gxsURLInfo::ToString() const

The URL without its fragment.

bool gxsURLInfo::IsSecure() const

True for https, ftps, smtps, pop3s, imaps and wss.