Page Speed Optimization Libraries  1.6.29.3
net/instaweb/automatic/public/proxy_interface.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00026 
00027 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00028 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00029 
00030 #include "net/instaweb/http/public/url_async_fetcher.h"
00031 #include "net/instaweb/util/public/basictypes.h"
00032 #include "net/instaweb/util/public/property_cache.h"
00033 #include "net/instaweb/util/public/scoped_ptr.h"
00034 #include "net/instaweb/util/public/string.h"
00035 #include "net/instaweb/util/public/string_util.h"
00036 
00037 namespace net_instaweb {
00038 
00039 class AsyncFetch;
00040 class GoogleUrl;
00041 class MessageHandler;
00042 class ProxyFetchPropertyCallbackCollector;
00043 class ProxyFetchFactory;
00044 class ServerContext;
00045 class RewriteOptions;
00046 class Statistics;
00047 class TimedVariable;
00048 class Timer;
00049 
00051 class ProxyInterface : public UrlAsyncFetcher {
00052  public:
00053   ProxyInterface(const StringPiece& hostname, int port,
00054                  ServerContext* server_context, Statistics* stats);
00055   virtual ~ProxyInterface();
00056 
00058   static void InitStats(Statistics* statistics);
00059 
00063   virtual void Fetch(const GoogleString& requested_url,
00064                      MessageHandler* handler,
00065                      AsyncFetch* async_fetch);
00066 
00068   bool IsWellFormedUrl(const GoogleUrl& url);
00069 
00070   static const char kCacheHtmlRequestCount[];
00071 
00073   virtual ProxyFetchPropertyCallbackCollector* InitiatePropertyCacheLookup(
00074       bool is_resource_fetch,
00075       const GoogleUrl& request_url,
00076       RewriteOptions* options,
00077       AsyncFetch* async_fetch,
00078       const bool requires_blink_cohort,
00079       bool* added_page_property_callback);
00080 
00081  protected:
00083   ServerContext* server_context_; 
00084 
00085  private:
00086   friend class ProxyInterfaceTest;
00087 
00091   void ProxyRequest(bool is_resource_fetch,
00092                     const GoogleUrl& requested_url,
00093                     AsyncFetch* async_fetch,
00094                     MessageHandler* handler);
00095 
00098   struct RequestData;
00099   void GetRewriteOptionsDone(RequestData* request_data,
00100                              RewriteOptions* query_options);
00101 
00102   PropertyCache::CohortVector GetCohortList(bool requires_blink_cohort) const;
00103 
00106   bool UrlAndPortMatchThisServer(const GoogleUrl& url);
00107 
00108   UrlAsyncFetcher* fetcher_; 
00109   Timer* timer_; 
00110 
00114   const GoogleString hostname_;
00115   const int port_;
00116 
00119   TimedVariable* all_requests_;
00121   TimedVariable* pagespeed_requests_;
00123   TimedVariable* cache_html_flow_requests_;
00125   TimedVariable* rejected_requests_;
00126 
00127   scoped_ptr<ProxyFetchFactory> proxy_fetch_factory_;
00128 
00129   DISALLOW_COPY_AND_ASSIGN(ProxyInterface);
00130 };
00131 
00132 }  
00133 
00134 #endif  ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines