Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
domain_rewrite_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_REWRITE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_REWRITE_FILTER_H_
21 
22 #include <utility>
23 #include <vector>
24 
36 
37 namespace net_instaweb {
38 
39 class Statistics;
40 class Variable;
41 
51  public:
52  static const char kStickyRedirectHeader[];
53 
54  DomainRewriteFilter(RewriteDriver* rewrite_driver, Statistics* stats);
56  static void InitStats(Statistics* statistics);
57  virtual void StartDocumentImpl();
58  virtual void EndDocument();
59  virtual void StartElementImpl(HtmlElement* element);
60  virtual void EndElementImpl(HtmlElement* element) {}
61 
62  virtual const char* Name() const { return "DomainRewrite"; }
63 
66  ScriptUsage GetScriptUsage() const override { return kMayInjectScripts; }
67 
68  enum RewriteResult {
69  kRewroteDomain,
70  kDomainUnchanged,
71  kFail,
72  };
73 
74  enum HeaderSource {
75  kHttp,
76  kMetaHttpEquiv
77  };
78 
79  typedef std::vector<std::pair<StringPiece, StringPiece> > SetCookieAttributes;
80 
88  static RewriteResult Rewrite(const StringPiece& input_url,
89  const GoogleUrl& base_url,
90  const ServerContext* server_context,
91  const RewriteOptions* options,
92  bool apply_sharding,
93  bool apply_domain_suffix,
94  GoogleString* output_url);
95 
103  static void UpdateDomainHeaders(const GoogleUrl& base_url,
104  const ServerContext* server_context,
105  const RewriteOptions* options,
106  ResponseHeaders* headers);
107 
110  static bool UpdateOneDomainHeader(HeaderSource src,
111  const GoogleUrl& base_url,
112  const ServerContext* server_context,
113  const RewriteOptions* options,
114  StringPiece name,
115  StringPiece value_in,
116  GoogleString* out);
117 
119  static bool UpdateSetCookieHeader(const GoogleUrl& base_url,
120  const ServerContext* server_context,
121  const RewriteOptions* options,
122  StringPiece value_in,
123  GoogleString* out);
124 
125 
131  static bool ParseRefreshContent(StringPiece input,
132  StringPiece* before,
133  StringPiece* url,
134  StringPiece* after);
135 
136 
142  static void ParseSetCookieAttributes(StringPiece input,
143  StringPiece* cookie_string,
144  SetCookieAttributes* attributes);
145 
146  private:
147  static void TryUpdateOneHttpDomainHeader(const GoogleUrl& base_url,
148  const ServerContext* server_context,
149  const RewriteOptions* options,
150  StringPiece name,
151  ResponseHeaders* headers);
152 
154  Variable* rewrite_count_;
155 
156 
157 };
158 
159 }
160 
161 #endif
Definition: common_filter.h:47
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
static RewriteResult Rewrite(const StringPiece &input_url, const GoogleUrl &base_url, const ServerContext *server_context, const RewriteOptions *options, bool apply_sharding, bool apply_domain_suffix, GoogleString *output_url)
Definition: html_element.h:42
static bool UpdateOneDomainHeader(HeaderSource src, const GoogleUrl &base_url, const ServerContext *server_context, const RewriteOptions *options, StringPiece name, StringPiece value_in, GoogleString *out)
static bool UpdateSetCookieHeader(const GoogleUrl &base_url, const ServerContext *server_context, const RewriteOptions *options, StringPiece value_in, GoogleString *out)
Like UpdateOneDomainHeader, but specifically for Set-Cookie.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: domain_rewrite_filter.h:62
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
static bool ParseRefreshContent(StringPiece input, StringPiece *before, StringPiece *url, StringPiece *after)
Definition: rewrite_driver.h:100
RewriteResult
Definition: rewrite_result.h:27
ScriptUsage GetScriptUsage() const override
Definition: domain_rewrite_filter.h:66
const GoogleUrl & base_url() const
Getters.
static void ParseSetCookieAttributes(StringPiece input, StringPiece *cookie_string, SetCookieAttributes *attributes)
Definition: domain_rewrite_filter.h:50
static void UpdateDomainHeaders(const GoogleUrl &base_url, const ServerContext *server_context, const RewriteOptions *options, ResponseHeaders *headers)