Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
instaweb_handler.h
Go to the documentation of this file.
1 // Copyright 2010 Google Inc.
19 
20 #ifndef PAGESPEED_APACHE_INSTAWEB_HANDLER_H_
21 #define PAGESPEED_APACHE_INSTAWEB_HANDLER_H_
22 
24 #include "net/instaweb/http/public/request_context.h"
27 #include "net/instaweb/rewriter/public/rewrite_query.h"
37 
38 #include "apr_pools.h"
43 
44 namespace net_instaweb {
45 
46 class ApacheConfig;
47 class ApacheRequestContext;
48 class ApacheRewriteDriverFactory;
49 class ApacheServerContext;
50 class InPlaceResourceRecorder;
51 
65  public:
66  explicit InstawebHandler(request_rec* request);
67  ~InstawebHandler();
68 
70  const GoogleUrl& stripped_gurl() const { return stripped_gurl_; }
71  const RequestContextPtr request_context() const { return request_context_; }
72  bool use_custom_options() const { return custom_options_.get() != NULL; }
73  const QueryParams& query_params() { return rewrite_query_.query_params(); }
74  const QueryParams& pagespeed_query_params() {
75  return rewrite_query_.pagespeed_query_params();
76  }
77  const QueryParams& pagespeed_option_cookies() {
78  return rewrite_query_.pagespeed_option_cookies();
79  }
80 
81  void RemoveStrippedResponseHeadersFromApacheRequest();
82 
88  RewriteDriver* MakeDriver();
89 
91  void DisownDriver();
92 
99  ApacheFetch* MakeFetch(
100  const GoogleString& url, bool buffered, StringPiece debug_info);
101 
104  ApacheFetch* MakeFetch(bool buffered, StringPiece debug_info) {
105  return MakeFetch(original_url_, buffered, debug_info);
106  }
107 
111  bool HandleAsProxy();
112 
115  void HandleAsProxyForAll();
116 
120  bool HandleAsInPlace();
121 
125 
129  void WaitForFetch();
130 
134  bool ProxyUrl();
135 
142  bool AuthenticateProxy();
143 
144  RequestHeaders* ReleaseRequestHeaders() { return request_headers_.release(); }
145 
148  const ApacheConfig* options() { return options_; }
149 
152  static bool is_pagespeed_subrequest(request_rec* request);
153 
156  static apr_status_t instaweb_handler(request_rec* request);
157 
161  static apr_status_t save_url_hook(request_rec *request);
162 
165  static apr_status_t save_url_in_note(request_rec *request,
166  ApacheServerContext* server_context);
167 
171  static apr_status_t instaweb_map_to_storage(request_rec* request);
172 
175  static void AboutToBeDoneWithRecorder(request_rec* request,
176  InPlaceResourceRecorder* recorder);
177 
178  private:
183  void ComputeCustomOptions();
184 
185  static bool IsCompressibleContentType(const char* content_type);
186 
187  static void send_out_headers_and_body(
188  request_rec* request,
189  const ResponseHeaders& response_headers,
190  const GoogleString& output);
191 
195  static bool handle_as_resource(ApacheServerContext* server_context,
196  request_rec* request,
197  GoogleUrl* gurl);
198 
201  static void write_handler_response(const StringPiece& output,
202  request_rec* request,
203  ContentType content_type,
204  const StringPiece& cache_control);
205  static void write_handler_response(const StringPiece& output,
206  request_rec* request);
207 
213  static const char* get_instaweb_resource_url(
214  request_rec* request, ApacheServerContext* server_context);
215 
219  static int log_request_headers(void* logging_data, const char* key,
220  const char* value);
221 
222  static void instaweb_static_handler(request_rec* request,
223  ApacheServerContext* server_context);
224 
225  static apr_status_t instaweb_statistics_handler(
226  request_rec* request, ApacheServerContext* server_context,
227  ApacheRewriteDriverFactory* factory);
228 
234  static bool parse_query_params(const request_rec* request, GoogleString* data,
235  apr_status_t* ret);
236 
240  static bool parse_body_from_post(const request_rec* request,
241  GoogleString* data, apr_status_t* ret);
242 
243  static apr_status_t instaweb_beacon_handler(
244  request_rec* request, ApacheServerContext* server_context);
245 
246  static bool IsBeaconUrl(const RewriteOptions::BeaconUrl& beacons,
247  const GoogleUrl& gurl);
248 
249  request_rec* request_;
250  RequestContextPtr request_context_;
251  ApacheRequestContext* apache_request_context_;
252  ApacheServerContext* server_context_;
253  scoped_ptr<RequestHeaders> request_headers_;
254  scoped_ptr<ResponseHeaders> response_headers_;
255  GoogleString original_url_;
256  GoogleUrl stripped_gurl_;
257  scoped_ptr<ApacheConfig> custom_options_;
258 
267  const ApacheConfig* options_;
268  RewriteDriver* rewrite_driver_;
269  bool driver_owned_;
270  int num_response_attributes_;
271  RewriteQuery rewrite_query_;
272  ApacheFetch* fetch_;
273 
274 
275 };
276 
277 }
278 
279 #endif
Definition: instaweb_handler.h:64
class GoogleUrl
Definition: google_url.h:58
Definition: apache_fetch.h:44
Definition: rewrite_query.h:41
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
Definition: in_place_resource_recorder.h:43
Definition: apache_config.h:31
static apr_status_t instaweb_map_to_storage(request_rec *request)
static bool is_pagespeed_subrequest(request_rec *request)
ApacheFetch * MakeFetch(const GoogleString &url, bool buffered, StringPiece debug_info)
Definition: rewrite_options.h:474
Read/write API for HTTP response headers.
Definition: response_headers.h:37
ApacheFetch * MakeFetch(bool buffered, StringPiece debug_info)
Definition: instaweb_handler.h:104
Definition: scoped_ptr.h:30
Definition: apache_server_context.h:52
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
RewriteDriver * MakeDriver()
const GoogleUrl & stripped_gurl() const
Any PageSpeed query params are removed.
Definition: instaweb_handler.h:70
Definition: rewrite_driver.h:100
static apr_status_t instaweb_handler(request_rec *request)
Definition: content_type.h:31
void DisownDriver()
Prevent "this" from cleaning up rewrite_driver_ at destruction.
static apr_status_t save_url_hook(request_rec *request)
static void AboutToBeDoneWithRecorder(request_rec *request, InPlaceResourceRecorder *recorder)
const ApacheConfig * options()
Definition: instaweb_handler.h:148
Creates an Apache RewriteDriver.
Definition: apache_rewrite_driver_factory.h:47
Definition: apache_request_context.h:37
static apr_status_t save_url_in_note(request_rec *request, ApacheServerContext *server_context)