#include <Uri.h>
![Collaboration graph](classAnyP_1_1Uri__coll__graph.png)
Public Member Functions | |
Uri () | |
Uri (AnyP::UriScheme const &aScheme) | |
Uri (const Uri &)=default | |
Uri (Uri &&)=default | |
Uri & | operator= (const Uri &)=default |
Uri & | operator= (Uri &&)=default |
void | clear () |
void | touch () |
clear the cached URI display forms More... | |
bool | parse (const HttpRequestMethod &, const SBuf &url) |
const AnyP::UriScheme & | getScheme () const |
void | setScheme (const AnyP::ProtocolType &p, const char *str) |
convert the URL scheme to that given More... | |
void | setScheme (const AnyP::UriScheme &s) |
void | userInfo (const SBuf &s) |
const SBuf & | userInfo () const |
void | host (const char *src) |
const char * | host (void) const |
int | hostIsNumeric (void) const |
const Ip::Address & | hostIP (void) const |
std::optional< Host > | parsedHost () const |
SBuf | hostOrIp () const |
void | port (const Port p) |
reset authority port subcomponent More... | |
Port | port () const |
authority port subcomponent More... | |
void | defaultPort () |
reset the port to the default port number for the current scheme More... | |
void | path (const char *p) |
void | path (const SBuf &p) |
const SBuf & | path () const |
void | addRelativePath (const char *relUrl) |
SBuf & | authority (bool requirePort=false) const |
SBuf & | absolute () const |
Static Public Member Functions | |
static char * | cleanup (const char *uri) |
static const SBuf & | SlashPath () |
the static '/' default URL-path More... | |
static const SBuf & | Asterisk () |
the static '*' pseudo-URI More... | |
static SBuf | Encode (const SBuf &, const CharacterSet &expected) |
static SBuf | Decode (const SBuf &) |
%-decode the given buffer More... | |
Private Member Functions | |
MEMPROXY_CLASS (Uri) | |
void | parseUrn (Parser::Tokenizer &) |
SBuf | parseHost (Parser::Tokenizer &) const |
int | parsePort (Parser::Tokenizer &) const |
Private Attributes | |
AnyP::UriScheme | scheme_ |
SBuf | userInfo_ |
char | host_ [SQUIDHOSTNAMELEN] |
string representation of the URI authority name or IP More... | |
bool | hostIsNumeric_ |
whether the authority 'host' is a raw-IP More... | |
Ip::Address | hostAddr_ |
binary representation of the URI authority if it is a raw-IP More... | |
Port | port_ |
authority port subcomponent More... | |
SBuf | path_ |
URI path segment. More... | |
SBuf | authorityHttp_ |
RFC 7230 section 5.3.3 authority, maybe without default-port. More... | |
SBuf | authorityWithPort_ |
RFC 7230 section 5.3.3 authority with explicit port. More... | |
SBuf | absolute_ |
RFC 7230 section 5.3.2 absolute-URI. More... | |
Detailed Description
Represents a Uniform Resource Identifier. Can store both URL or URN representations.
Governed by RFC 3986
Constructor & Destructor Documentation
◆ Uri() [1/4]
◆ Uri() [2/4]
AnyP::Uri::Uri | ( | AnyP::UriScheme const & | aScheme | ) |
◆ Uri() [3/4]
|
default |
◆ Uri() [4/4]
|
default |
Member Function Documentation
◆ absolute()
SBuf & AnyP::Uri::absolute | ( | ) | const |
The absolute-form URI for currently stored values.
As defined by RFC 7230 section 5.3.3 this form omits the userinfo@ field from RFC 3986 defined authority segments when the protocol scheme is http: or https:.
Definition at line 711 of file Uri.cc.
References MAX_URL, AnyP::PROTO_FTP, AnyP::PROTO_UNKNOWN, AnyP::PROTO_URN, CharacterSet::remove(), CharacterSet::rename(), SBuf::reserveCapacity(), and UserInfoChars().
Referenced by asnCacheStart(), HttpRequest::effectiveRequestUri(), CacheManager::ParseUrl(), purgeEntriesByHeader(), UrnState::setUriResFromRequest(), and urnParseReply().
◆ addRelativePath()
void AnyP::Uri::addRelativePath | ( | const char * | relUrl | ) |
Merge a relative-path URL into the existing URI details. Implements RFC 3986 section 5.2.3
The caller must ensure relUrl is a valid relative-path.
NP: absolute-path are also accepted, but path() method should be used instead when possible.
Definition at line 836 of file Uri.cc.
References SBuf::npos, and AnyP::PROTO_URN.
Referenced by purgeEntriesByHeader().
◆ Asterisk()
|
static |
Definition at line 109 of file Uri.cc.
Referenced by urlCheckRequest().
◆ authority()
SBuf & AnyP::Uri::authority | ( | bool | requirePort = false | ) | const |
The authority-form URI for currently stored values.
As defined by RFC 7230 section 5.3.3 this form omits the userinfo@ field from RFC 3986 defined authority segment.
- Parameters
-
requirePort when true the port will be included, otherwise port will be elided when it is the default for the current scheme.
Definition at line 689 of file Uri.cc.
References SBuf::append(), SBuf::appendf(), and port.
Referenced by Http::One::Server::buildHttpRequest(), ClientHttpRequest::checkForInternalAccess(), copyOneHeaderFromClientsideRequestToUpstreamRequest(), HttpRequest::effectiveRequestUri(), HttpStateData::httpBuildRequestHeader(), internalRemoteUri(), AnyP::operator<<(), peerAllowedToUse(), Ssl::ServerBump::ServerBump(), and Http::Tunneler::Tunneler().
◆ cleanup()
|
static |
- Returns
- a new URI that honors uri_whitespace
Definition at line 1033 of file Uri.cc.
References assert, Config, MAX_URL, rfc1738_do_escape(), RFC1738_ESCAPE_NOSPACE, RFC1738_ESCAPE_UNESCAPED, rfc1738_escape_unescaped, SquidConfig::uri_whitespace, URI_WHITESPACE_ALLOW, URI_WHITESPACE_CHOP, URI_WHITESPACE_DENY, URI_WHITESPACE_ENCODE, URI_WHITESPACE_STRIP, w_space, xfree, xisspace, xmalloc, and xstrndup().
Referenced by ClientHttpRequest::setLogUriToRawUri().
◆ clear()
|
inline |
Definition at line 43 of file Uri.h.
References host_, hostAddr_, hostIsNumeric_, port_, AnyP::PROTO_NONE, scheme_, Ip::Address::setEmpty(), and touch().
Referenced by HttpRequest::clean(), and HttpRequest::init().
◆ Decode()
Definition at line 86 of file Uri.cc.
References SBuf::append(), CharacterSet::complement(), and Here.
Referenced by Acl::UrlCheck::match(), Acl::UrlLoginCheck::match(), and TestUri::testEncoding().
◆ defaultPort()
|
inline |
Definition at line 94 of file Uri.h.
References defaultPort(), getScheme(), and port().
Referenced by asnCacheStart(), and defaultPort().
◆ Encode()
|
static |
%-encode characters in a buffer which do not conform to the provided set of expected characters.
Governed by RFC 3986 section 2.1
Definition at line 57 of file Uri.cc.
References SBuf::append(), SBuf::appendf(), Parser::Tokenizer::atEnd(), SBuf::isEmpty(), SBuf::length(), Parser::Tokenizer::prefix(), Parser::Tokenizer::remaining(), SBuf::reserveSpace(), and Parser::Tokenizer::skip().
Referenced by ErrorState::Dump(), and TestUri::testEncoding().
◆ getScheme()
|
inline |
Definition at line 58 of file Uri.h.
References scheme_.
Referenced by Format::Format::assemble(), clientReplyContext::cacheHit(), HttpRequest::canonicalCleanUrl(), carpSelectParent(), ClientHttpRequest::checkForInternalAccess(), clientHierarchical(), ErrorState::compileLegacyCode(), defaultPort(), FwdState::dispatch(), HttpRequest::effectiveRequestUri(), ClientRequestContext::hostHeaderVerify(), HttpStateData::httpBuildRequestHeader(), HttpRequest::maybeCacheable(), AnyP::operator<<(), HttpStateData::processReplyHeader(), purgeEntriesByHeader(), FwdState::secureConnectionToPeerIfNeeded(), PeerSelector::selectSomeDirect(), FwdState::Start(), TestUri::testConstructScheme(), TestHttpRequest::testCreateFromUrl(), TestUri::testDefaultConstructor(), TestHttpRequest::testIPv6HostColonBug(), urlCheckRequest(), and Ftp::UrlWith2f().
◆ host() [1/2]
void AnyP::Uri::host | ( | const char * | src | ) |
Definition at line 123 of file Uri.cc.
References debugs, and xstrncpy().
Referenced by asnCacheStart(), Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), ConnStateData::buildFakeRequest(), carpSelectParent(), HttpStateData::checkDateSkew(), ClientHttpRequest::checkForInternalAccess(), PeerSelector::checkNetdbDirect(), ErrorState::compileLegacyCode(), TunnelStateData::connectDone(), FwdState::connectStart(), FwdState::dispatch(), doV2Query(), ftpSendUser(), TunnelStateData::getHost(), ClientRequestContext::hostHeaderVerify(), htcpTstReply(), clientReplyContext::identifyFoundObject(), internalRemoteUri(), ACLDestinationIP::match(), neighborType(), netdbClosestParent(), netdbUpdatePeer(), FwdState::noteConnection(), TunnelStateData::noteConnection(), PeerSelector::noteIps(), operator<<(), CacheManager::ParseUrl(), PeerPoolMgr::PeerPoolMgr(), ConnStateData::pinConnection(), ConnStateData::postHttpsAccept(), HttpStateData::processReplyBody(), clientReplyContext::purgeRequest(), PeerSelector::resolveSelected(), PeerSelector::selectMore(), PeerSelector::selectSomeParent(), UrnState::setUriResFromRequest(), TunnelStateData::startConnecting(), ACLDestinationIP::StartLookup(), FwdState::successfullyConnectedToPeer(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), urlCanonicalFakeHttps(), urnParseReply(), FwdState::usePinned(), and TunnelStateData::usePinned().
◆ host() [2/2]
|
inline |
◆ hostIP()
|
inline |
◆ hostIsNumeric()
|
inline |
Definition at line 77 of file Uri.h.
References hostIsNumeric_.
Referenced by ACLDestinationIP::match().
◆ hostOrIp()
SBuf AnyP::Uri::hostOrIp | ( | ) | const |
- Returns
- the host subcomponent of the authority component If the host is an IPv6 address, returns that IP address with [brackets]. See RFC 3986 Section 3.2.2.
Definition at line 139 of file Uri.cc.
References MAX_IPSTRLEN.
Referenced by ConnStateData::initiateTunneledRequest().
◆ MEMPROXY_CLASS()
|
private |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ parse()
bool AnyP::Uri::parse | ( | const HttpRequestMethod & | method, |
const SBuf & | url | ||
) |
Definition at line 295 of file Uri.cc.
References SquidConfig::allow_underscore, SquidConfig::appendDomainLen, Assure, B, SquidConfig::check_hostnames, Config, CurrentException(), DBG_IMPORTANT, debugs, AnyP::UriScheme::defaultPort(), Here, AnyP::UriScheme::image(), SBuf::length(), LOCAL_ARRAY, MAX_URL, Http::METHOD_CONNECT, Http::METHOD_OPTIONS, Http::METHOD_TRACE, MYNAME, SquidConfig::onoff, port, AnyP::PROTO_HTTP, AnyP::PROTO_NONE, AnyP::PROTO_URN, SBuf::rawContent(), rfc1738_escape_unescaped, rfc1738_unescape(), SBufToCstring(), stringHasWhitespace(), SquidConfig::uri_whitespace, URI_WHITESPACE_ALLOW, URI_WHITESPACE_CHOP, URI_WHITESPACE_DENY, URI_WHITESPACE_ENCODE, URI_WHITESPACE_STRIP, uriParseScheme(), urlAppendDomain(), valid_hostname_chars, valid_hostname_chars_u, w_space, xisspace, xstrncpy(), and xtolower.
Referenced by ClientRequestContext::clientRedirectDone(), HttpRequest::FromUrl(), HttpRequest::parseFirstLine(), and urnParseReply().
◆ parsedHost()
std::optional< AnyP::Host > AnyP::Uri::parsedHost | ( | ) | const |
Successfully interpreted non-empty host subcomponent of the authority component (if any). XXX: Remove hostOrIp() and print Host instead.
Definition at line 150 of file Uri.cc.
References debugs, SBuf::find(), SBuf::npos, AnyP::Host::ParseIp(), and AnyP::Host::ParseSimpleDomainName().
Referenced by ConnStateData::serveDelayedError().
◆ parseHost()
|
private |
Extracts and returns a (suspected but only partially validated) uri-host IPv6address, IPv4address, or reg-name component. This function uses (and quotes) RFC 3986, Section 3.2.2 syntax rules.
Definition at line 601 of file Uri.cc.
References SBuf::c_str(), SBuf::find(), Ip::Address::fromHost(), Here, CharacterSet::HEXDIG, SBuf::npos, and CharacterSet::TCHAR.
◆ parsePort()
|
private |
Extracts and returns an RFC 3986 URI authority port value (with additional restrictions). The RFC defines port as a possibly empty sequence of decimal digits. We reject certain ports (that are syntactically valid from the RFC point of view) because we are worried that Squid and other traffic handlers may dangerously mishandle unusual (and virtually always bogus) port numbers. Rejected ports cannot be successfully used by Squid itself.
◆ parseUrn()
|
private |
Governed by RFC 8141 section 2:
assigned-name = "urn" ":" NID ":" NSS NID = (alphanum) 0*30(ldh) (alphanum) ldh = alphanum / "-" NSS = pchar *(pchar / "/")
RFC 3986 Appendix D.2 defines (as deprecated):
alphanum = ALPHA / DIGIT
Notice that NID is exactly 2-32 characters in length.
Definition at line 570 of file Uri.cc.
References CharacterSet::ALPHA, SBuf::begin(), SBuf::c_str(), debugs, CharacterSet::DIGIT, Here, SBuf::length(), AnyP::PROTO_URN, and SBuf::rbegin().
◆ path() [1/3]
const SBuf & AnyP::Uri::path | ( | ) | const |
Definition at line 169 of file Uri.cc.
References AnyP::PROTO_HTTP, and AnyP::PROTO_HTTPS.
◆ path() [2/3]
|
inline |
Definition at line 96 of file Uri.h.
References path_, and touch().
Referenced by asnCacheStart(), Format::Format::assemble(), HttpStateData::buildRequestPrefix(), carpSelectParent(), ClientHttpRequest::checkForInternalAccess(), ErrorState::compileLegacyCode(), ftpFail(), ftpReadType(), ftpSendType(), ftpTrySlashHack(), HttpRequest::initHTTP(), internalStart(), AnyP::operator<<(), HttpRequest::pack(), HttpRequest::packFirstLineInto(), CacheManager::ParseUrl(), HttpRequest::prefixLen(), purgeEntriesByHeader(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), urlCheckRequest(), Ftp::UrlWith2f(), Adaptation::Service::wants(), and whoisStart().
◆ path() [3/3]
|
inline |
◆ port() [1/2]
|
inline |
◆ port() [2/2]
|
inline |
Definition at line 90 of file Uri.h.
References port_, and touch().
Referenced by Format::Format::assemble(), ConnStateData::borrowPinnedConnection(), ConnStateData::buildFakeRequest(), carpSelectParent(), ClientHttpRequest::checkForInternalAccess(), ErrorState::compileLegacyCode(), ClientRequestContext::hostHeaderVerify(), ConnStateData::initiateTunneledRequest(), internalRemoteUri(), PeerSelector::noteIp(), peerAllowedToUse(), ConnStateData::pinConnection(), ConnStateData::postHttpsAccept(), TestHttpRequest::testCreateFromUrl(), TestHttpRequest::testIPv6HostColonBug(), TestCacheManager::testParseUrl(), and urlCanonicalFakeHttps().
◆ setScheme() [1/2]
|
inline |
Definition at line 61 of file Uri.h.
References scheme_, and touch().
Referenced by ConnStateData::buildFakeRequest(), ClientHttpRequest::checkForInternalAccess(), HttpRequest::initHTTP(), and TestCacheManager::testParseUrl().
◆ setScheme() [2/2]
|
inline |
◆ SlashPath()
◆ touch()
void const AnyP::Uri::touch | ( | ) |
Definition at line 681 of file Uri.cc.
Referenced by clear(), path(), port(), setScheme(), and userInfo().
◆ userInfo() [1/2]
|
inline |
◆ userInfo() [2/2]
|
inline |
Definition at line 70 of file Uri.h.
References touch(), and userInfo_.
Referenced by clientInterpretRequestHeaders(), HttpStateData::httpBuildRequestHeader(), netdbExchangeStart(), and peerDigestRequest().
Member Data Documentation
◆ absolute_
◆ authorityHttp_
◆ authorityWithPort_
◆ host_
|
private |
◆ hostAddr_
|
private |
◆ hostIsNumeric_
|
private |
Definition at line 178 of file Uri.h.
Referenced by clear(), and hostIsNumeric().
◆ path_
◆ port_
|
private |
◆ scheme_
|
private |
- The scheme of this URL. This has the 'type code' smell about it. In future we may want to make the methods that dispatch based on the scheme virtual and have a class per protocol.
- On the other hand, having Protocol as an explicit concept is useful, see for instance the ACLProtocol acl type. One way to represent this is to have one prototype URL with no host etc for each scheme, another is to have an explicit scheme class, and then each URL class could be a subclass of the scheme. Another way is one instance of a AnyP::UriScheme class instance for each URL scheme we support, and one class for each manner of treating the scheme : a Hierarchical URL, a non-hierarchical URL etc.
- Deferring the decision, its a type code for now. RBC 20060507.
- In order to make taking any of these routes easy, scheme is private, only settable at construction time, or with explicit setter
Definition at line 171 of file Uri.h.
Referenced by clear(), getScheme(), and setScheme().
◆ userInfo_
|
private |
Definition at line 173 of file Uri.h.
Referenced by userInfo().
The documentation for this class was generated from the following files:
- src/anyp/Uri.h
- src/anyp/Uri.cc
- src/tests/stub_libanyp.cc
Introduction
- About Squid
- Why Squid?
- Squid Developers
- How to Donate
- How to Help Out
- Getting Squid
- Squid Source Packages
- Squid Deployment Case-Studies
- Squid Software Foundation
Documentation
- Quick Setup
- Configuration:
- FAQ and Wiki
- Guide Books:
- Non-English
- More...
Support
- Security Advisories
- Bugzilla Database
- Mailing lists
- Contacting us
- Commercial services
- Project Sponsors
- Squid-based products