Page Speed Optimization Libraries
1.7.30.4
|
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 RequestHeaders; 00045 class RewriteDriver; 00046 class RewriteOptions; 00047 00048 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url"; 00049 00051 template <class T> 00052 apr_status_t apache_cleanup(void* object) { 00053 T* resolved = static_cast<T*>(object); 00054 delete resolved; 00055 return APR_SUCCESS; 00056 } 00057 00068 class InstawebContext { 00069 public: 00070 enum ContentEncoding { kNone, kGzip, kDeflate, kOther }; 00071 enum ContentDetectionState { kStart, kHtml, kNotHtml }; 00072 00074 InstawebContext(request_rec* request, 00075 RequestHeaders* request_headers, 00076 const ContentType& content_type, 00077 ApacheServerContext* server_context, 00078 const GoogleString& base_url, 00079 const RequestContextPtr& request_context, 00080 bool use_custom_options, 00081 const RewriteOptions& options); 00082 ~InstawebContext(); 00083 00084 void Rewrite(const char* input, int size); 00085 void Flush(); 00086 void Finish(); 00087 00088 apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; } 00089 ContentEncoding content_encoding() const { return content_encoding_; } 00090 ApacheServerContext* apache_server_context() { return server_context_; } 00091 const GoogleString& output() { return output_; } 00092 bool empty() const { return output_.empty(); } 00093 void clear() { output_.clear(); } 00094 00095 ResponseHeaders* response_headers() { 00096 return &response_headers_; 00097 } 00098 00099 bool sent_headers() { return sent_headers_; } 00100 void set_sent_headers(bool sent) { sent_headers_ = sent; } 00101 00103 void PopulateHeaders(request_rec* request); 00104 00108 static ApacheServerContext* ServerContextFromServerRec(server_rec* server); 00109 00111 static const char* MakeRequestUrl(const RewriteOptions& global_options, 00112 request_rec* request); 00113 00114 private: 00115 void ComputeContentEncoding(request_rec* request); 00116 void BlockingPropertyCacheLookup(); 00117 void ProcessBytes(const char* input, int size); 00118 00123 void SetExperimentStateAndCookie(request_rec* request, 00124 RewriteOptions* options); 00125 00126 GoogleString output_; 00127 apr_bucket_brigade* bucket_brigade_; 00128 ContentEncoding content_encoding_; 00129 const ContentType content_type_; 00130 00131 ApacheServerContext* server_context_; 00132 RewriteDriver* rewrite_driver_; 00133 StringWriter string_writer_; 00134 scoped_ptr<GzipInflater> inflater_; 00135 HtmlDetector html_detector_; 00136 GoogleString absolute_url_; 00137 scoped_ptr<RequestHeaders> request_headers_; 00138 ResponseHeaders response_headers_; 00139 bool started_parse_; 00140 bool sent_headers_; 00141 bool populated_headers_; 00142 00143 DISALLOW_COPY_AND_ASSIGN(InstawebContext); 00144 }; 00145 00146 } 00147 00148 #endif ///< NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_