Page Speed Optimization Libraries  1.8.31.3
net/instaweb/apache/instaweb_context.h
Go to the documentation of this file.
00001 // Copyright 2010 Google Inc.
00017 
00018 #ifndef NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
00019 #define NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
00020 
00021 #include "net/instaweb/automatic/public/html_detector.h"
00022 #include "net/instaweb/http/public/content_type.h"
00023 #include "net/instaweb/http/public/request_context.h"
00024 #include "net/instaweb/http/public/response_headers.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/util/public/scoped_ptr.h"
00027 #include "net/instaweb/util/public/string.h"
00028 #include "net/instaweb/util/public/string_writer.h"
00029 
00033 #include "httpd.h"
00034 #include "apr_pools.h"
00035 
00036 struct apr_bucket_brigade;
00037 struct request_rec;
00038 struct server_rec;
00039 
00040 namespace net_instaweb {
00041 
00042 class ApacheServerContext;
00043 class GzipInflater;
00044 class QueryParams;
00045 class RequestHeaders;
00046 class RewriteDriver;
00047 class RewriteOptions;
00048 
00049 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url";
00050 
00052 template <class T>
00053 apr_status_t apache_cleanup(void* object) {
00054   T* resolved = static_cast<T*>(object);
00055   delete resolved;
00056   return APR_SUCCESS;
00057 }
00058 
00069 class InstawebContext {
00070  public:
00071   enum ContentEncoding { kNone, kGzip, kDeflate, kOther };
00072   enum ContentDetectionState { kStart, kHtml, kNotHtml };
00073 
00075   InstawebContext(request_rec* request,
00076                   RequestHeaders* request_headers,
00077                   const ContentType& content_type,
00078                   ApacheServerContext* server_context,
00079                   const GoogleString& base_url,
00080                   const RequestContextPtr& request_context,
00081                   const QueryParams& pagespeed_query_params,
00082                   const QueryParams& pagespeed_option_cookies,
00083                   bool use_custom_options,
00084                   const RewriteOptions& options);
00085   ~InstawebContext();
00086 
00087   void Rewrite(const char* input, int size);
00088   void Flush();
00089   void Finish();
00090 
00091   apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; }
00092   ContentEncoding content_encoding() const { return  content_encoding_; }
00093   ApacheServerContext* apache_server_context() { return server_context_; }
00094   const GoogleString& output() { return output_; }
00095   bool empty() const { return output_.empty(); }
00096   void clear() { output_.clear(); }  
00097 
00098   ResponseHeaders* response_headers() {
00099     return &response_headers_;
00100   }
00101 
00102   bool sent_headers() { return sent_headers_; }
00103   void set_sent_headers(bool sent) { sent_headers_ = sent; }
00104 
00106   void PopulateHeaders(request_rec* request);
00107 
00111   static ApacheServerContext* ServerContextFromServerRec(server_rec* server);
00112 
00114   static const char* MakeRequestUrl(const RewriteOptions& global_options,
00115                                     request_rec* request);
00116 
00117  private:
00118   void ComputeContentEncoding(request_rec* request);
00119   void BlockingPropertyCacheLookup();
00120   void ProcessBytes(const char* input, int size);
00121 
00126   void SetExperimentStateAndCookie(request_rec* request,
00127                                    RewriteOptions* options);
00128 
00129   GoogleString output_; 
00130   apr_bucket_brigade* bucket_brigade_;
00131   ContentEncoding content_encoding_;
00132   const ContentType content_type_;
00133 
00134   ApacheServerContext* server_context_;
00135   RewriteDriver* rewrite_driver_;
00136   StringWriter string_writer_;
00137   scoped_ptr<GzipInflater> inflater_;
00138   HtmlDetector html_detector_;
00139   GoogleString absolute_url_;
00140   scoped_ptr<RequestHeaders> request_headers_;
00141   ResponseHeaders response_headers_;
00142   bool started_parse_;
00143   bool sent_headers_;
00144   bool populated_headers_;
00145 
00146   DISALLOW_COPY_AND_ASSIGN(InstawebContext);
00147 };
00148 
00149 }  
00150 
00151 #endif  ///< NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines