Page Speed Optimization Libraries
1.2.24.1
|
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/response_headers.h" 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/property_cache.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_util.h" 00029 #include "net/instaweb/util/public/string_writer.h" 00030 #include "net/instaweb/util/public/thread_system.h" 00031 00035 #include "httpd.h" 00036 #include "apr_pools.h" 00037 00038 struct apr_bucket_brigade; 00039 struct request_rec; 00040 struct server_rec; 00041 00042 namespace net_instaweb { 00043 00044 class ApacheServerContext; 00045 class GzipInflater; 00046 class RequestHeaders; 00047 class RewriteDriver; 00048 class RewriteOptions; 00049 00050 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url"; 00051 00053 class PropertyCallback : public PropertyPage { 00054 public: 00055 PropertyCallback(RewriteDriver* driver, 00056 ThreadSystem* thread_system, 00057 const StringPiece& key); 00058 00059 virtual void Done(bool success); 00060 00061 void BlockUntilDone(); 00062 00063 private: 00064 RewriteDriver* driver_; 00065 GoogleString url_; 00066 bool done_; 00067 scoped_ptr<ThreadSystem::CondvarCapableMutex> mutex_; 00068 scoped_ptr<ThreadSystem::Condvar> condvar_; 00069 DISALLOW_COPY_AND_ASSIGN(PropertyCallback); 00070 }; 00071 00082 class InstawebContext { 00083 public: 00084 enum ContentEncoding { kNone, kGzip, kDeflate, kOther }; 00085 enum ContentDetectionState { kStart, kHtml, kNotHtml }; 00086 00088 InstawebContext(request_rec* request, 00089 RequestHeaders* request_headers, 00090 const ContentType& content_type, 00091 ApacheServerContext* server_context, 00092 const GoogleString& base_url, 00093 bool using_spdy, 00094 bool use_custom_options, 00095 const RewriteOptions& options); 00096 ~InstawebContext(); 00097 00098 void Rewrite(const char* input, int size); 00099 void Flush(); 00100 void Finish(); 00101 00102 apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; } 00103 ContentEncoding content_encoding() const { return content_encoding_; } 00104 ApacheServerContext* apache_server_context() { return server_context_; } 00105 const GoogleString& output() { return output_; } 00106 bool empty() const { return output_.empty(); } 00107 void clear() { output_.clear(); } 00108 00109 ResponseHeaders* response_headers() { 00110 return &response_headers_; 00111 } 00112 00113 bool sent_headers() { return sent_headers_; } 00114 void set_sent_headers(bool sent) { sent_headers_ = sent; } 00115 00117 void PopulateHeaders(request_rec* request); 00118 00122 static ApacheServerContext* ServerContextFromServerRec(server_rec* server); 00123 00125 static const char* MakeRequestUrl(const RewriteOptions& options, 00126 request_rec* request); 00127 00128 bool modify_caching_headers() const { return modify_caching_headers_; } 00129 00130 private: 00131 void ComputeContentEncoding(request_rec* request); 00132 00135 PropertyCallback* InitiatePropertyCacheLookup(); 00136 void ProcessBytes(const char* input, int size); 00137 00142 void SetFuriousStateAndCookie(request_rec* request, RewriteOptions* options); 00143 00144 static apr_status_t Cleanup(void* object); 00145 00146 GoogleString output_; 00147 apr_bucket_brigade* bucket_brigade_; 00148 ContentEncoding content_encoding_; 00149 const ContentType content_type_; 00150 00151 ApacheServerContext* server_context_; 00152 RewriteDriver* rewrite_driver_; 00153 StringWriter string_writer_; 00154 scoped_ptr<GzipInflater> inflater_; 00155 HtmlDetector html_detector_; 00156 GoogleString absolute_url_; 00157 scoped_ptr<RequestHeaders> request_headers_; 00158 ResponseHeaders response_headers_; 00159 bool started_parse_; 00160 bool sent_headers_; 00161 bool populated_headers_; 00162 bool modify_caching_headers_; 00163 00164 DISALLOW_COPY_AND_ASSIGN(InstawebContext); 00165 }; 00166 00167 } 00168 00169 #endif ///< NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_