00001
00017
00018 #ifndef NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
00019 #define NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_
00020
00021 #include "base/scoped_ptr.h"
00022 #include "net/instaweb/apache/apache_rewrite_driver_factory.h"
00023 #include "net/instaweb/automatic/public/html_detector.h"
00024 #include "net/instaweb/http/public/content_type.h"
00025 #include "net/instaweb/http/public/request_headers.h"
00026 #include "net/instaweb/http/public/response_headers.h"
00027 #include "net/instaweb/rewriter/public/rewrite_driver.h"
00028 #include "net/instaweb/util/public/string.h"
00029 #include "net/instaweb/util/public/string_writer.h"
00030
00034 #include "httpd.h"
00035
00036 namespace net_instaweb {
00037
00038 class ApacheResourceManager;
00039 class GzipInflater;
00040 class RewriteOptions;
00041
00042 const char kPagespeedOriginalUrl[] = "mod_pagespeed_original_url";
00043
00054 class InstawebContext {
00055 public:
00056 enum ContentEncoding { kNone, kGzip, kDeflate, kOther };
00057 enum ContentDetectionState { kStart, kHtml, kNotHtml };
00058
00060 InstawebContext(request_rec* request,
00061 RequestHeaders* request_headers,
00062 const ContentType& content_type,
00063 ApacheResourceManager* manager,
00064 const GoogleString& base_url,
00065 bool use_custom_options,
00066 const RewriteOptions& options);
00067 ~InstawebContext();
00068
00069 void Rewrite(const char* input, int size);
00070 void Flush();
00071 void Finish();
00072
00073 apr_bucket_brigade* bucket_brigade() const { return bucket_brigade_; }
00074 ContentEncoding content_encoding() const { return content_encoding_; }
00075 ApacheResourceManager* manager() { return resource_manager_; }
00076 const GoogleString& output() { return output_; }
00077 bool empty() const { return output_.empty(); }
00078 void clear() { output_.clear(); }
00079
00080 ResponseHeaders* response_headers() {
00081 return &response_headers_;
00082 }
00083
00084 bool sent_headers() { return sent_headers_; }
00085 void set_sent_headers(bool sent) { sent_headers_ = sent; }
00086
00088 void PopulateHeaders(request_rec* request);
00089
00093 static ApacheResourceManager* ManagerFromServerRec(server_rec* server);
00094
00096 static const char* MakeRequestUrl(request_rec* request);
00097
00098 private:
00099 void ComputeContentEncoding(request_rec* request);
00100 void ProcessBytes(const char* input, int size);
00101
00106 void SetFuriousStateAndCookie(request_rec* request, RewriteOptions* options);
00107
00108 static apr_status_t Cleanup(void* object);
00109
00110 GoogleString output_;
00111 apr_bucket_brigade* bucket_brigade_;
00112 ContentEncoding content_encoding_;
00113 const ContentType content_type_;
00114
00115 ApacheResourceManager* resource_manager_;
00116 RewriteDriver* rewrite_driver_;
00117 StringWriter string_writer_;
00118 scoped_ptr<GzipInflater> inflater_;
00119 HtmlDetector html_detector_;
00120 GoogleString absolute_url_;
00121 scoped_ptr<RequestHeaders> request_headers_;
00122 ResponseHeaders response_headers_;
00123 bool started_parse_;
00124 bool sent_headers_;
00125 bool populated_headers_;
00126
00127 DISALLOW_COPY_AND_ASSIGN(InstawebContext);
00128 };
00129
00130 }
00131
00132 #endif ///< NET_INSTAWEB_APACHE_INSTAWEB_CONTEXT_H_