Page Speed Optimization Libraries  1.13.35.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 PAGESPEED_APACHE_INSTAWEB_CONTEXT_H_
19 #define PAGESPEED_APACHE_INSTAWEB_CONTEXT_H_
20 
21 #include "net/instaweb/http/public/request_context.h"
28 
33 #include "apr_pools.h"
34 
35 namespace net_instaweb {
36 
37 class ApacheServerContext;
38 class GzipInflater;
39 class QueryParams;
40 class RequestHeaders;
41 class ResponseHeaders;
42 class RewriteDriver;
43 class RewriteOptions;
44 
45 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url";
46 
48 template <class T>
49 apr_status_t apache_cleanup(void* object) {
50  T* resolved = static_cast<T*>(object);
51  delete resolved;
52  return APR_SUCCESS;
53 }
54 
66  public:
67  enum ContentEncoding { kNone, kGzip, kDeflate, kOther };
68  enum ContentDetectionState { kStart, kHtml, kNotHtml };
69 
71  InstawebContext(request_rec* request,
72  RequestHeaders* request_headers,
73  const ContentType& content_type,
74  ApacheServerContext* server_context,
75  const GoogleString& base_url,
76  const RequestContextPtr& request_context,
77  const QueryParams& pagespeed_query_params,
78  const QueryParams& pagespeed_option_cookies,
79  bool use_custom_options,
80  const RewriteOptions& options);
81  ~InstawebContext();
82 
83  void Rewrite(const char* input, int size);
84  void Flush();
85  void Finish();
86 
87  apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; }
88  ContentEncoding content_encoding() const { return content_encoding_; }
89  ApacheServerContext* apache_server_context() { return server_context_; }
90  const GoogleString& output() { return output_; }
91  bool empty() const { return output_.empty(); }
92  void clear() { output_.clear(); }
93 
95  return response_headers_.get();
96  }
97 
98  bool sent_headers() { return sent_headers_; }
99  void set_sent_headers(bool sent) { sent_headers_ = sent; }
100 
102  void PopulateHeaders(request_rec* request);
103 
107  static ApacheServerContext* ServerContextFromServerRec(server_rec* server);
108 
110  static const char* MakeRequestUrl(const RewriteOptions& global_options,
111  request_rec* request);
112 
113  private:
114  void ComputeContentEncoding(request_rec* request);
115  void BlockingPropertyCacheLookup();
116  void ProcessBytes(const char* input, int size);
117 
122  void SetExperimentStateAndCookie(request_rec* request,
123  RewriteOptions* options);
124 
125  GoogleString output_;
126  apr_bucket_brigade* bucket_brigade_;
127  ContentEncoding content_encoding_;
128  const ContentType content_type_;
129 
130  ApacheServerContext* server_context_;
131  RewriteDriver* rewrite_driver_;
132  StringWriter string_writer_;
133  scoped_ptr<GzipInflater> inflater_;
134  HtmlDetector html_detector_;
135  GoogleString absolute_url_;
136  scoped_ptr<RequestHeaders> request_headers_;
137  scoped_ptr<ResponseHeaders> response_headers_;
138  bool started_parse_;
139  bool sent_headers_;
140  bool populated_headers_;
141 
142 
143 };
144 
145 }
146 
147 #endif
Parses and rewrites URL query parameters.
Definition: query_params.h:31
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
Definition: instaweb_context.h:65
apr_status_t apache_cleanup(void *object)
Generic deleter meant to be used with apr_pool_cleanup_register().
Definition: instaweb_context.h:49
Read/write API for HTTP response headers.
Definition: response_headers.h:37
static ApacheServerContext * ServerContextFromServerRec(server_rec *server)
Definition: apache_server_context.h:52
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static const char * MakeRequestUrl(const RewriteOptions &global_options, request_rec *request)
Returns a fetchable URI from a request, using the request pool.
Definition: content_type.h:31
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:84
ResponseHeaders * response_headers()
Definition: instaweb_context.h:94