Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rewrite_query.h
1 // Copyright 2011 Google Inc.
14 
15 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_QUERY_H_
16 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_QUERY_H_
17 
18 #include "net/instaweb/rewriter/public/device_properties.h"
19 #include "net/instaweb/http/public/request_context.h"
28 
29 namespace net_instaweb {
30 
31 class GoogleUrl;
32 class MessageHandler;
33 class RequestProperties;
34 class ResponseHeaders;
35 class RewriteDriver;
36 class RewriteDriverFactory;
37 class RewriteFilter;
38 class RewriteOptions;
39 class ServerContext;
40 
41 class RewriteQuery {
42  public:
44  static const char kModPagespeed[];
45  static const char kPageSpeed[];
46  static const char kModPagespeedFilters[];
47  static const char kPageSpeedFilters[];
52  static const char kNoscriptValue[];
53 
54  enum Status {
55  kSuccess,
56  kInvalid,
57  kNoneFound
58  };
59 
60  RewriteQuery();
61  ~RewriteQuery();
62 
89  Status Scan(bool allow_related_options,
90  bool allow_options_to_be_specified_by_cookies,
91  const GoogleString& request_option_override,
92  const RequestContextPtr& request_context,
93  RewriteDriverFactory* factory,
94  ServerContext* server_context,
95  GoogleUrl* request_url,
96  RequestHeaders* request_headers,
97  ResponseHeaders* response_headers,
98  MessageHandler* handler);
99 
107  template <class HeaderT>
108  static Status ScanHeader(bool allow_options,
109  const GoogleString& request_option_override,
110  const RequestContextPtr& request_context,
111  HeaderT* headers,
112  RequestProperties* request_properties,
113  RewriteOptions* options,
114  MessageHandler* handler);
115 
116 
121  static GoogleString GenerateResourceOption(StringPiece filter_id,
122  RewriteDriver* driver);
123 
126  static bool MightBeCustomOption(StringPiece name);
127 
128  const QueryParams& query_params() const { return query_params_; }
129  const QueryParams& pagespeed_query_params() const {
130  return pagespeed_query_params_;
131  }
132  const QueryParams& pagespeed_option_cookies() const {
133  return pagespeed_option_cookies_;
134  }
135  const RewriteOptions* options() const { return options_.get(); }
136  RewriteOptions* ReleaseOptions() { return options_.release(); }
137 
140  static bool IsOK(Status status) {
141  return (status == kNoneFound) || (status == kSuccess);
142  }
143 
144  private:
145  friend class RewriteQueryTest;
146  FRIEND_TEST(RewriteQueryTest, ClientOptionsEmptyHeader);
147  FRIEND_TEST(RewriteQueryTest, ClientOptionsMultipleHeaders);
148  FRIEND_TEST(RewriteQueryTest, ClientOptionsOrder1);
149  FRIEND_TEST(RewriteQueryTest, ClientOptionsOrder2);
150  FRIEND_TEST(RewriteQueryTest, ClientOptionsCaseInsensitive);
151  FRIEND_TEST(RewriteQueryTest, ClientOptionsNonDefaultProxyMode);
152  FRIEND_TEST(RewriteQueryTest, ClientOptionsValidVersionBadOptions);
153  FRIEND_TEST(RewriteQueryTest, ClientOptionsInvalidVersion);
154 
155  enum ProxyMode {
157  kProxyModeDefault,
159  kProxyModeNoImageTransform,
162  kProxyModeNoTransform,
163  };
164 
168  static bool MayHaveCustomOptions(
169  const QueryParams& params, const RequestHeaders* req_headers,
170  const ResponseHeaders* resp_headers,
171  const RequestHeaders::CookieMultimap& cookies);
172 
174  template <class HeaderT>
175  static bool HeadersMayHaveCustomOptions(const QueryParams& params,
176  const HeaderT* headers);
177 
179  static bool CookiesMayHaveCustomOptions(
180  const RequestHeaders::CookieMultimap& cookies);
181 
183  static Status ScanNameValue(const StringPiece& name,
184  const StringPiece& value,
185  bool allow_options,
186  const RequestContextPtr& request_context,
187  RequestProperties* request_properties,
188  RewriteOptions* options,
189  MessageHandler* handler);
190 
192  static Status ParseResourceOption(StringPiece value, RewriteOptions* options,
193  const RewriteFilter* rewrite_filter);
194 
197  static bool ParseClientOptions(
198  const StringPiece& client_options,
199  ProxyMode* proxy_mode,
201 
204  static bool SetEffectiveImageQualities(
205  DeviceProperties::ImageQualityPreference quality_preference,
206  RequestProperties* request_properties,
207  RewriteOptions* options);
208 
210  static bool UpdateRewriteOptionsWithClientOptions(
211  StringPiece header_value, RequestProperties* request_properties,
212  RewriteOptions* options);
213 
215  static bool ParseProxyMode(const GoogleString* mode_name, ProxyMode* mode);
216 
218  static bool ParseImageQualityPreference(
219  const GoogleString* preference_name,
221 
222  QueryParams query_params_;
223  QueryParams pagespeed_query_params_;
224  QueryParams pagespeed_option_cookies_;
225  scoped_ptr<RewriteOptions> options_;
226 
227 
228 };
229 
230 }
231 
232 #endif
class GoogleUrl
Definition: google_url.h:58
static const char kModPagespeed[]
The names of query-params.
Definition: rewrite_query.h:44
Parses and rewrites URL query parameters.
Definition: query_params.h:31
ImageQualityPreference
Definition: device_properties.h:69
Definition: rewrite_query.h:41
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
static Status ScanHeader(bool allow_options, const GoogleString &request_option_override, const RequestContextPtr &request_context, HeaderT *headers, RequestProperties *request_properties, RewriteOptions *options, MessageHandler *handler)
Read/write API for HTTP response headers.
Definition: response_headers.h:37
static GoogleString GenerateResourceOption(StringPiece filter_id, RewriteDriver *driver)
static const char kNoscriptValue[]
Definition: rewrite_query.h:52
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static bool IsOK(Status status)
Definition: rewrite_query.h:140
Definition: rewrite_driver.h:100
Definition: server_context.h:99
Definition: message_handler.h:39
Status Scan(bool allow_related_options, bool allow_options_to_be_specified_by_cookies, const GoogleString &request_option_override, const RequestContextPtr &request_context, RewriteDriverFactory *factory, ServerContext *server_context, GoogleUrl *request_url, RequestHeaders *request_headers, ResponseHeaders *response_headers, MessageHandler *handler)
static bool MightBeCustomOption(StringPiece name)
Definition: rewrite_options.h:84
Definition: request_properties.h:37
Definition: rewrite_driver_factory.h:70