proxygen
|
#include <Uri.h>
Public Member Functions | |
Uri (StringPiece str) | |
const std::string & | scheme () const |
const std::string & | username () const |
const std::string & | password () const |
const std::string & | host () const |
std::string | hostname () const |
uint16_t | port () const |
const std::string & | path () const |
const std::string & | query () const |
const std::string & | fragment () const |
std::string | authority () const |
template<class String > | |
String | toString () const |
std::string | str () const |
fbstring | fbstr () const |
void | setPort (uint16_t port) |
const std::vector< std::pair< std::string, std::string > > & | getQueryParams () |
Private Attributes | |
std::string | scheme_ |
std::string | username_ |
std::string | password_ |
std::string | host_ |
bool | hasAuthority_ |
uint16_t | port_ |
std::string | path_ |
std::string | query_ |
std::string | fragment_ |
std::vector< std::pair< std::string, std::string > > | queryParams_ |
Class representing a URI.
Consider http://www.facebook.com/foo/bar?key=foo#anchor
The URI is broken down into its parts: scheme ("http"), authority (ie. host and port, in most cases: "www.facebook.com"), path ("/foo/bar"), query ("key=foo") and fragment ("anchor"). The scheme is lower-cased.
If this Uri represents a URL, note that, to prevent ambiguity, the component parts are NOT percent-decoded; you should do this yourself with uriUnescape() (for the authority and path) and uriUnescape(..., UriEscapeMode::QUERY) (for the query, but probably only after splitting at '&' to identify the individual parameters).
|
explicit |
Parse a Uri from a string. Throws std::invalid_argument on parse error.
Definition at line 35 of file Uri.cpp.
References authority(), folly::Range< Iter >::begin(), folly::Range< Iter >::empty(), folly::Range< Iter >::end(), folly::gen::first, fragment_, hasAuthority_, host_, password_, path_, port(), port_, query_, regex, scheme_, folly::pushmi::operators::transform, UNLIKELY, and username_.
std::string folly::Uri::authority | ( | ) | const |
Definition at line 96 of file Uri.cpp.
References folly::empty(), host(), password(), port(), folly::size(), string, folly::toAppend(), and username().
Referenced by fragment(), TEST(), and Uri().
|
inline |
|
inline |
Definition at line 85 of file Uri.h.
References authority(), fragment_, string, and toString().
Referenced by folly::uri_detail::as_tuple(), and TEST().
const std::vector< std::pair< std::string, std::string > > & folly::Uri::getQueryParams | ( | ) |
Get query parameters as key-value pairs. e.g. for URI containing query string: key1=foo&key2=&key3&=bar&=bar= In returned list, there are 3 entries: "key1" => "foo" "key2" => "" "key3" => "" Parts "=bar" and "=bar=" are ignored, as they are not valid query parameters. "=bar" is missing parameter name, while "=bar=" has more than one equal signs, we don't know which one is the delimiter for key and value.
Note, this method is not thread safe, it might update internal state, but only the first call to this method update the state. After the first call is finished, subsequent calls to this method are thread safe.
Definition at line 132 of file Uri.cpp.
References folly::gen::first, query_, queryParams_, regex, and string.
Referenced by BENCHMARK(), setPort(), and TEST().
|
inline |
Get host part of URI. If host is an IPv6 address, square brackets will be returned, for example: "[::1]".
Definition at line 63 of file Uri.h.
References host_, hostname(), and string.
Referenced by folly::uri_detail::as_tuple(), authority(), and TEST().
std::string folly::Uri::hostname | ( | ) | const |
Get host part of URI. If host is an IPv6 address, square brackets will not be returned, for exmaple "::1"; otherwise it returns the same thing as host().
hostname() is what one needs to call if passing the host to any other tool or API that connects to that host/port; e.g. getaddrinfo() only understands IPv6 host without square brackets
Definition at line 123 of file Uri.cpp.
References host_.
|
inline |
Definition at line 56 of file Uri.h.
References password_.
Referenced by folly::uri_detail::as_tuple(), authority(), and TEST().
|
inline |
Definition at line 79 of file Uri.h.
References path_.
Referenced by folly::uri_detail::as_tuple(), and TEST().
|
inline |
Definition at line 76 of file Uri.h.
References port_.
Referenced by folly::uri_detail::as_tuple(), authority(), setPort(), TEST(), and Uri().
|
inline |
Definition at line 82 of file Uri.h.
References query_.
Referenced by folly::uri_detail::as_tuple(), and TEST().
|
inline |
Definition at line 50 of file Uri.h.
References scheme_.
Referenced by folly::uri_detail::as_tuple(), and TEST().
|
inline |
Definition at line 101 of file Uri.h.
References getQueryParams(), hasAuthority_, port(), and port_.
|
inline |
String folly::Uri::toString | ( | ) | const |
|
inline |
Definition at line 53 of file Uri.h.
References username_.
Referenced by folly::uri_detail::as_tuple(), authority(), and TEST().
|
private |
Definition at line 137 of file Uri.h.
Referenced by fragment(), and Uri().
|
private |
|
private |
Definition at line 132 of file Uri.h.
Referenced by host(), hostname(), and Uri().
|
private |
Definition at line 131 of file Uri.h.
Referenced by password(), and Uri().
|
private |
|
private |
|
private |
Definition at line 136 of file Uri.h.
Referenced by getQueryParams(), query(), and Uri().
|
private |
Definition at line 138 of file Uri.h.
Referenced by getQueryParams().
|
private |
|
private |
Definition at line 130 of file Uri.h.
Referenced by Uri(), and username().