Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::GoogleUrl Class Reference

class GoogleUrl More...

#include "google_url.h"

Public Member Functions

 GoogleUrl (const GoogleString &spec)
 
 GoogleUrl (StringPiece sp)
 
 GoogleUrl (const char *str)
 
 GoogleUrl (const GoogleUrl &base, const GoogleString &relative)
 
 GoogleUrl (const GoogleUrl &base, StringPiece relative)
 
 GoogleUrl (const GoogleUrl &base, const char *relative)
 
void Swap (GoogleUrl *google_url)
 
bool Reset (StringPiece new_url)
 
bool Reset (const GoogleUrl &new_url)
 
bool Reset (const GoogleUrl &base, const GoogleString &relative)
 
bool Reset (const GoogleUrl &base, StringPiece relative)
 
bool Reset (const GoogleUrl &base, const char *relative)
 
void Clear ()
 Resets this URL to be invalid.
 
bool IsWebValid () const
 Is a valid web (HTTP or HTTPS) URL. Most users will want this.
 
bool IsWebOrDataValid () const
 Also allows data: URLs.
 
bool IsAnyValid () const
 
GoogleUrlCopyAndAddQueryParam (StringPiece unescaped_name, StringPiece unescaped_value) const
 
GoogleUrlCopyAndAddEscapedQueryParam (StringPiece escaped_name, StringPiece escaped_value) const
 
StringPiece AllExceptQuery () const
 
StringPiece AllAfterQuery () const
 
StringPiece AllExceptLeaf () const
 
StringPiece LeafWithQuery () const
 
StringPiece LeafSansQuery () const
 
StringPiece PathAndLeaf () const
 
StringPiece PathSansLeaf () const
 
StringPiece PathSansQuery () const
 
StringPiece NetPath () const
 
GoogleString ExtractFileName () const
 
StringPiece Host () const
 
StringPiece HostAndPort () const
 
StringPiece Origin () const
 
StringPiece Query () const
 
StringPiece Scheme () const
 Returns scheme of stored url.
 
StringPiece Spec () const
 It is illegal to call this for invalid urls (check IsWebValid() first).
 
StringPiece UncheckedSpec () const
 Returns gurl_.spec_ without checking to see if it's valid or empty.
 
const char * spec_c_str () const
 This method is primarily for printf purposes.
 
int IntPort () const
 
int EffectiveIntPort () const
 Returns the effective port number, which is dependent on the scheme.
 
bool is_empty () const
 
bool has_scheme () const
 
bool has_path () const
 
bool has_query () const
 
bool SchemeIs (const char *lower_ascii_scheme) const
 
bool SchemeIs (StringPiece lower_ascii_scheme) const
 
StringPiece Relativize (UrlRelativity url_relativity, const GoogleUrl &base_url) const
 
bool operator== (const GoogleUrl &other) const
 Defiant equality operator!
 
bool operator!= (const GoogleUrl &other) const
 

Static Public Member Functions

static int DefaultPortForScheme (StringPiece scheme)
 
static UrlRelativity FindRelativity (StringPiece url)
 Find out how relative the URL string is.
 
static GoogleString UnescapeQueryParam (StringPiece escaped)
 
static GoogleString UnescapeIgnorePlus (StringPiece escaped)
 
static GoogleString EscapeQueryParam (StringPiece unescaped)
 
static GoogleString Sanitize (StringPiece url)
 
static GoogleString CanonicalizePath (StringPiece path)
 

Detailed Description

class GoogleUrl

Constructor & Destructor Documentation

net_instaweb::GoogleUrl::GoogleUrl ( const GoogleUrl base,
const GoogleString relative 
)

The following three constructors create a new GoogleUrl by resolving the String(Piece) against the base.

Member Function Documentation

StringPiece net_instaweb::GoogleUrl::AllAfterQuery ( ) const

For "http://a.com/b/c/d?e=f#r" returns "#r" For "http://a.com/b/c/d?e=f#r1#r2" returns "#r1#r2" AllExceptQuery() + Query() + AllAfterQuery() = Spec() when url is valid Different from Parsed.ref in the case of multiple "#"s after "?" Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::AllExceptLeaf ( ) const

For "http://a.com/b/c/d?e=f/g" returns "http://a.com/b/c/", including trailing slash. Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::AllExceptQuery ( ) const

For "http://a.com/b/c/d?e=f/g#r" returns "http://a.com/b/c/d" Returns a StringPiece, only valid for the lifetime of this object.

static GoogleString net_instaweb::GoogleUrl::CanonicalizePath ( StringPiece  path)
static

Returns the canonical representation of a given path component of URL. Will also prepend / if it's not there. This will follow the same rules for what's in %-encoded form and what isn't as GoogleUrl does.

GoogleUrl* net_instaweb::GoogleUrl::CopyAndAddEscapedQueryParam ( StringPiece  escaped_name,
StringPiece  escaped_value 
) const

Same as CopyAndAddQueryParam() but name and value must already be escaped. Most users should use CopyAndAddQueryParam() instead for safety.

GoogleUrl* net_instaweb::GoogleUrl::CopyAndAddQueryParam ( StringPiece  unescaped_name,
StringPiece  unescaped_value 
) const

Returns a new GoogleUrl that is identical to this one but with additional query param. Name and value should both be unescaped. This is a factory method that returns a pointer, the caller is responsible for the management of the new object's memory (the caller owns the pointer).

static int net_instaweb::GoogleUrl::DefaultPortForScheme ( StringPiece  scheme)
static

Returns the default port for given scheme, or url::PORT_UNSPECIFIED if the scheme isn't recognized. Scheme is expected to be in lowercase.

static GoogleString net_instaweb::GoogleUrl::EscapeQueryParam ( StringPiece  unescaped)
static

Escapes a string for use in a URL query param.

This function escapes reserved chars (ex: '/', ':', '?', '&', etc.).

GoogleString net_instaweb::GoogleUrl::ExtractFileName ( ) const

Extracts the filename portion of the path and returns it. The filename is everything after the last slash in the path. This may be empty.

StringPiece net_instaweb::GoogleUrl::HostAndPort ( ) const

For "http://a.com/b/c.html" returns "a.com". For "http://a.com:1234/b/c.html" returns "a.com:1234".

bool net_instaweb::GoogleUrl::IsAnyValid ( ) const

Only use for you don't care about scheme, just need to know that URL is well-formed. Note: This will accept things like "foo:bar".

StringPiece net_instaweb::GoogleUrl::LeafSansQuery ( ) const

For "http://a.com/b/c/d?e=f/g" returns "d", omitting leading slash. Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::LeafWithQuery ( ) const

For "http://a.com/b/c/d?e=f/g" returns "d?e=f/g", omitting leading slash. Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::NetPath ( ) const

Scheme-relative URL. Spec() == Scheme() + ":" + NetPath(). Named based on http://tools.ietf.org/html/rfc1808#section-2.2 For "http://a.com/b/c/d?E=f/g#r" returns "//a.com/b/c/d?E=f/g#r". For "file:///tmp/foo" returns "///tmp/foo".

StringPiece net_instaweb::GoogleUrl::Origin ( ) const

For "http://a.com/b/c/d?e=f/g returns "http://a.com" without trailing slash Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::PathAndLeaf ( ) const

For "http://a.com/b/c/d?E=f/g" returns "/b/c/d?e=f/g" including leading slash Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::PathSansLeaf ( ) const

For "http://a.com/b/c/d/g.html" returns "/b/c/d/" including leading and trailing slashes. For queries, "http://a.com/b/c/d?E=f/g" returns "/b/c/". Returns a StringPiece, only valid for the lifetime of this object.

StringPiece net_instaweb::GoogleUrl::PathSansQuery ( ) const

For "http://a.com/b/c/d?E=f/g returns "/b/c/d" including leading slash, and excluding the query.

StringPiece net_instaweb::GoogleUrl::Query ( ) const

Returns the query-string, not including the "?". Note that the query will be in escaped syntax, and is suitable for passing to QueryParams for parsing and unescaping.

StringPiece net_instaweb::GoogleUrl::Relativize ( UrlRelativity  url_relativity,
const GoogleUrl base_url 
) const

If possible, produce a URL as relative as url_relativity, relative to base_url. If not possible, simply returns the absolute URL string. Returns a StringPiece, only valid for the lifetime of this object.

It is illegal to call this for invalid urls (check IsWebValid() first).

static GoogleString net_instaweb::GoogleUrl::Sanitize ( StringPiece  url)
static

Produces a sanitary, escaped version of a URL. The URL may already have some mix of escaped and non-escaped sections. This function is idempotent and can safely be used on any URL without changing the meaning according to RFC 3986.

Result will not contain: 0x00-0x1F SPC "<>\^`{|} 0x7F-0xFF Result may contain: a-z A-Z 0-9 -._~:/?#[]@!$&'()*+,;=%

bool net_instaweb::GoogleUrl::SchemeIs ( StringPiece  lower_ascii_scheme) const
inline
Todo:
TODO(nforman): get GURL to take a StringPiece so we don't have to do any copying.
static GoogleString net_instaweb::GoogleUrl::UnescapeIgnorePlus ( StringPiece  escaped)
inlinestatic

UnescapeQueryParam converts "+" to " ", but that is not correct for other parts of a URL.

static GoogleString net_instaweb::GoogleUrl::UnescapeQueryParam ( StringPiece  escaped)
inlinestatic

Unescape a query parameter, converting all XX to the the actual char 0xXX. This also converts '+' to ' ' which is valid only in query parameters. For example, this will convert "foo%21bar+baz" to "foo!bar baz".

This will work with strings that have embedded NULs and %00s.

Todo:
TODO(jmarantz): Change signature to return a bool so if the escaped syntax was not valid, we can help the caller avoid relying on this value.

The documentation for this class was generated from the following file: