Page Speed Optimization Libraries
1.3.25.1
|
Public Member Functions | |
bool | MapRequestToDomain (const GoogleUrl &original_request, const StringPiece &resource_url, GoogleString *mapped_domain_name, GoogleUrl *resolved_request, MessageHandler *handler) const |
bool | IsDomainAuthorized (const GoogleUrl &original_request, const GoogleUrl &domain_to_check) const |
bool | IsOriginKnown (const GoogleUrl &domain_to_check) const |
bool | MapOrigin (const StringPiece &in, GoogleString *out, bool *is_proxy) const |
bool | MapOriginUrl (const GoogleUrl &gurl, GoogleString *out, bool *is_proxy) const |
bool | AddDomain (const StringPiece &domain_name, MessageHandler *handler) |
bool | AddRewriteDomainMapping (const StringPiece &to_domain, const StringPiece &comma_separated_from_domains, MessageHandler *handler) |
bool | AddTwoProtocolRewriteDomainMapping (const StringPiece &to_domain_name, const StringPiece &from_domain_name, MessageHandler *handler) |
bool | AddOriginDomainMapping (const StringPiece &to_domain, const StringPiece &comma_separated_from_domains, MessageHandler *handler) |
bool | AddProxyDomainMapping (const StringPiece &proxy_domain, const StringPiece &origin_domain, const StringPiece &to_domain_name, MessageHandler *handler) |
bool | AddTwoProtocolOriginDomainMapping (const StringPiece &to_domain_name, const StringPiece &from_domain_name, MessageHandler *handler) |
bool | AddShard (const StringPiece &to_domain, const StringPiece &comma_separated_shards, MessageHandler *handler) |
bool | ShardDomain (const StringPiece &domain_name, uint32 hash, GoogleString *sharded_domain) const |
void | Merge (const DomainLawyer &src) |
bool | WillDomainChange (const StringPiece &domain_name) const |
bool | can_rewrite_domains () const |
int | num_wildcarded_domains () const |
Visible for testing. | |
bool | DoDomainsServeSameContent (const StringPiece &domain1, const StringPiece &domain2) const |
void | FindDomainsRewrittenTo (const GoogleUrl &domain_name, ConstStringStarVector *from_domains) const |
GoogleString | Signature () const |
GoogleString | ToString (StringPiece line_prefix) const |
GoogleString | ToString () const |
Version that's easier to call from debugger. |
bool net_instaweb::DomainLawyer::AddDomain | ( | const StringPiece & | domain_name, |
MessageHandler * | handler | ||
) |
The methods below this comment are intended only to be run only at configuration time. Adds a simple domain to the set that can be rewritten. No mapping or sharding will be performed. Returns false if the domain syntax was not acceptable. Wildcards (*, ?) may be used in the domain_name. Careless use of wildcards can expose the user to XSS attacks.
bool net_instaweb::DomainLawyer::AddOriginDomainMapping | ( | const StringPiece & | to_domain, |
const StringPiece & | comma_separated_from_domains, | ||
MessageHandler * | handler | ||
) |
Adds a domain mapping, to assist with fetching resources from locally signficant names/ip-addresses.
Wildcards may not be used in the to_domain, but they can be used in the from_domains.
This routine can be called multiple times for the same to_domain. If the 'from' domains overlap due to wildcards, this will not be detected.
It is invalid to use the same origin_domain in AddProxyDomainMapping and as the to_domain of AddOriginDomainMapping. The latter requires a Host: request-header on fetches, whereas the former will not get one.
bool net_instaweb::DomainLawyer::AddProxyDomainMapping | ( | const StringPiece & | proxy_domain, |
const StringPiece & | origin_domain, | ||
const StringPiece & | to_domain_name, | ||
MessageHandler * | handler | ||
) |
Adds a mapping to enable proxying & optimizing resources hosted on a domain we do not control, going back to the origin to fetch them.
Wildcards may not be used in the proxy_domain or origin_domain.
Subdirectories should normally be used in the proxy_domain, the origin_domain, and to_domain. This is a not a strict requirement. If you fully control the entire origin domain and are dedicating a proxy domain for the sole use of that origin domain then subdirectories are not needed.
The proxy_domain must be running mod_pagespeed and configured consistently. The resources will be referenced from this domain in CSS and HTML files.
The origin_domain does not need to run mod_pagespeed; it is used to fetch the resources.
If to_domain is provided then resources are rewritten to to_domain instead of proxy_domain. This is useful for rewriting to a CDN.
It is invalid to use the same origin_domain in AddProxyDomainMapping and to_domain of AddOriginDomainMapping. The latter requires a overriding the Host: request-header on fetches.
bool net_instaweb::DomainLawyer::AddRewriteDomainMapping | ( | const StringPiece & | to_domain, |
const StringPiece & | comma_separated_from_domains, | ||
MessageHandler * | handler | ||
) |
Adds a domain mapping, to assist with serving resources from cookieless domains or CDNs. This implicitly calls AddDomain(to_domain) and AddDomain(from_domain) if necessary. If either 'to' or 'from' has invalid syntax then this function returns false and has no effect.
Wildcards may not be used in the to_domain, but they can be used in the from_domains.
This routine can be called multiple times for the same to_domain. If the 'from' domains overlap due to wildcards, this will not be detected.
bool net_instaweb::DomainLawyer::AddShard | ( | const StringPiece & | to_domain, |
const StringPiece & | comma_separated_shards, | ||
MessageHandler * | handler | ||
) |
Specifies domain-sharding. This implicitly calls AddDomain(to_domain).
Wildcards may not be used in the to_domain or the from_domain.
bool net_instaweb::DomainLawyer::AddTwoProtocolOriginDomainMapping | ( | const StringPiece & | to_domain_name, |
const StringPiece & | from_domain_name, | ||
MessageHandler * | handler | ||
) |
Adds domain mappings that handle fetches on both http and https for the given from_domain. No wildcards may be used in either domain, and both must be protocol-free and should not have port numbers.
This routine can be called multiple times for the same to_domain.
bool net_instaweb::DomainLawyer::AddTwoProtocolRewriteDomainMapping | ( | const StringPiece & | to_domain_name, |
const StringPiece & | from_domain_name, | ||
MessageHandler * | handler | ||
) |
Adds domain mappings that handle both http and https urls for the given from_domain_name. No wildcards may be used in either domain, and both must be protocol-free and should not have port numbers.
This routine can be called multiple times for the same to_domain.
bool net_instaweb::DomainLawyer::can_rewrite_domains | ( | ) | const [inline] |
Determines whether any resources might be domain-mapped, either via sharding or rewriting.
bool net_instaweb::DomainLawyer::DoDomainsServeSameContent | ( | const StringPiece & | domain1, |
const StringPiece & | domain2 | ||
) | const |
Determines whether two domains have been declared as serving the same content by the user, via Rewrite or Shard mapping.
void net_instaweb::DomainLawyer::FindDomainsRewrittenTo | ( | const GoogleUrl & | domain_name, |
ConstStringStarVector * | from_domains | ||
) | const |
Finds domains rewritten to this domain. Includes only non-wildcarded domains. comma_separated_from_domains is empty if no mapping found.
bool net_instaweb::DomainLawyer::IsDomainAuthorized | ( | const GoogleUrl & | original_request, |
const GoogleUrl & | domain_to_check | ||
) | const |
Given the context of an HTTP request to 'original_request', checks whether 'domain_to_check' is authorized for rewriting.
For example, if we are rewriting http://www.myhost.com/index.html, then all resources from www.myhost.com are implicitly authorized for rewriting. Additionally, any domains specified via AddDomain() are also authorized.
bool net_instaweb::DomainLawyer::IsOriginKnown | ( | const GoogleUrl & | domain_to_check | ) | const |
Returns true if the given origin (domain:port) is one that we were explicitly told about in any form --- e.g. as a rewrite domain, origin domain, simple domain, or a shard.
Note that this method returning true does not mean that resources from the given domain should be rewritten.
bool net_instaweb::DomainLawyer::MapOrigin | ( | const StringPiece & | in, |
GoogleString * | out, | ||
bool * | is_proxy | ||
) | const |
Maps an origin resource; just prior to fetching it. This fails if the input URL is not valid. It succeeds even if there is no mapping done. You must compare 'in' to 'out' to determine if mapping was done.
is_proxy is set to true if the origin-domain was established via AddProxyDomainMapping.
bool net_instaweb::DomainLawyer::MapRequestToDomain | ( | const GoogleUrl & | original_request, |
const StringPiece & | resource_url, | ||
GoogleString * | mapped_domain_name, | ||
GoogleUrl * | resolved_request, | ||
MessageHandler * | handler | ||
) | const |
Determines whether a resource can be rewritten, and returns the domain that it should be written to. The domain and the path of the resolved request are considered - first just the domain, then the domain plus the root of the path, and so on down the path until a match is found or the path is exhausted; this is done because we can map to a domain plus a path and we want to retain the previous behavior of 'working' when a mapped-to domain was provided. If the resource_url is relative (has no domain) then the resource can always be written, and will share the domain of the original request.
The resource_url is considered relative to original_request. Generally it is always accessible to rewrite resources in the same domain as the original.
Note: The mapped domain name will not incorporate any sharding. This is handled by ShardDomain().
The returned mapped_domain_name will always end with a slash on success. The returned resolved_request incorporates rewrite-domain mapping and the original URL.
Returns false on failure.
This is used both for domain authorization and domain rewriting, but not domain sharding.
See also IsDomainAuthorized, which can be used to determine domain authorization without performing a mapping.
void net_instaweb::DomainLawyer::Merge | ( | const DomainLawyer & | src | ) |
Merge the domains declared in src into this. There are no exclusions, so this is really just aggregating the mappings and authorizations declared in both domains. When the same domain is mapped in 'this' and 'src', 'src' wins.
bool net_instaweb::DomainLawyer::ShardDomain | ( | const StringPiece & | domain_name, |
uint32 | hash, | ||
GoogleString * | sharded_domain | ||
) | const |
Computes a domain shard based on a passed-in hash, returning true if the domain was sharded. Output argument 'sharded_domain' is only updated if when the return value is true.
The hash is an explicit uint32 so that we get the same shard for a resource, whether the server is 32-bit or 64-bit. If we have 5 shards and used size_t for hashes, then we'd wind up with different shards on 32-bit and 64-bit machines and that would reduce cacheability of the sharded resources.
Computes a signature for the DomainLawyer object including containing classes (Domain).
GoogleString net_instaweb::DomainLawyer::ToString | ( | StringPiece | line_prefix | ) | const |
Computes a string representation meant for debugging purposes only. (The format might change in unpredictable ways and is not meant for machine consumption). Each domain will appear on a separate line, and each line will be prefixed with 'line_prefix'.
bool net_instaweb::DomainLawyer::WillDomainChange | ( | const StringPiece & | domain_name | ) | const |
Determines whether a resource of the given domain name is going to change due to RewriteDomain mapping or domain sharding. Note that this does not account for the actual domain shard selected.