Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
instaweb_context.h
Go to the documentation of this file.
1 // Copyright 2010 Google Inc.
17 
18 #ifndef NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
19 #define NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
20 
28 
32 #include "httpd.h"
33 #include "apr_pools.h"
34 
35 struct apr_bucket_brigade;
36 struct request_rec;
37 struct server_rec;
38 
39 namespace net_instaweb {
40 
41 class ApacheServerContext;
42 class GzipInflater;
43 class QueryParams;
44 class RequestHeaders;
45 class ResponseHeaders;
46 class RewriteDriver;
47 class RewriteOptions;
48 
49 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url";
50 
52 template <class T>
53 apr_status_t apache_cleanup(void* object) {
54  T* resolved = static_cast<T*>(object);
55  delete resolved;
56  return APR_SUCCESS;
57 }
58 
70  public:
71  enum ContentEncoding { kNone, kGzip, kDeflate, kOther };
72  enum ContentDetectionState { kStart, kHtml, kNotHtml };
73 
75  InstawebContext(request_rec* request,
76  RequestHeaders* request_headers,
77  const ContentType& content_type,
78  ApacheServerContext* server_context,
79  const GoogleString& base_url,
80  const RequestContextPtr& request_context,
81  const QueryParams& pagespeed_query_params,
82  const QueryParams& pagespeed_option_cookies,
83  bool use_custom_options,
84  const RewriteOptions& options);
85  ~InstawebContext();
86 
87  void Rewrite(const char* input, int size);
88  void Flush();
89  void Finish();
90 
91  apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; }
92  ContentEncoding content_encoding() const { return content_encoding_; }
93  ApacheServerContext* apache_server_context() { return server_context_; }
94  const GoogleString& output() { return output_; }
95  bool empty() const { return output_.empty(); }
96  void clear() { output_.clear(); }
97 
98  ResponseHeaders* response_headers() {
99  return response_headers_.get();
100  }
101 
102  bool sent_headers() { return sent_headers_; }
103  void set_sent_headers(bool sent) { sent_headers_ = sent; }
104 
106  void PopulateHeaders(request_rec* request);
107 
111  static ApacheServerContext* ServerContextFromServerRec(server_rec* server);
112 
114  static const char* MakeRequestUrl(const RewriteOptions& global_options,
115  request_rec* request);
116 
117  private:
118  void ComputeContentEncoding(request_rec* request);
119  void BlockingPropertyCacheLookup();
120  void ProcessBytes(const char* input, int size);
121 
126  void SetExperimentStateAndCookie(request_rec* request,
127  RewriteOptions* options);
128 
129  GoogleString output_;
130  apr_bucket_brigade* bucket_brigade_;
131  ContentEncoding content_encoding_;
132  const ContentType content_type_;
133 
134  ApacheServerContext* server_context_;
135  RewriteDriver* rewrite_driver_;
136  StringWriter string_writer_;
137  scoped_ptr<GzipInflater> inflater_;
138  HtmlDetector html_detector_;
139  GoogleString absolute_url_;
140  scoped_ptr<RequestHeaders> request_headers_;
141  scoped_ptr<ResponseHeaders> response_headers_;
142  bool started_parse_;
143  bool sent_headers_;
144  bool populated_headers_;
145 
146  DISALLOW_COPY_AND_ASSIGN(InstawebContext);
147 };
148 
149 }
150 
151 #endif
Definition: instaweb_context.h:69
apr_status_t apache_cleanup(void *object)
Generic deleter meant to be used with apr_pool_cleanup_register().
Definition: instaweb_context.h:53
static ApacheServerContext * ServerContextFromServerRec(server_rec *server)
Definition: apache_server_context.h:49
static const char * MakeRequestUrl(const RewriteOptions &global_options, request_rec *request)
Returns a fetchable URI from a request, using the request pool.
InstawebContext(request_rec *request, RequestHeaders *request_headers, const ContentType &content_type, ApacheServerContext *server_context, const GoogleString &base_url, const RequestContextPtr &request_context, const QueryParams &pagespeed_query_params, const QueryParams &pagespeed_option_cookies, bool use_custom_options, const RewriteOptions &options)
Takes ownership of request_headers.
void PopulateHeaders(request_rec *request)
Populated response_headers_ with the request's headers_out table.
Definition: rewrite_options.h:81
ResponseHeaders * response_headers()
Definition: instaweb_context.h:98