00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00033
00034 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00035 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00036
00037 #include <utility>
00038
00039 #include "base/scoped_ptr.h"
00040 #include "net/instaweb/http/public/url_async_fetcher.h"
00041 #include "net/instaweb/util/public/basictypes.h"
00042 #include "net/instaweb/util/public/string.h"
00043 #include "net/instaweb/util/public/string_util.h"
00044
00045 namespace net_instaweb {
00046
00047 class AsyncFetch;
00048 class GoogleUrl;
00049 class MessageHandler;
00050 class ProxyFetchPropertyCallbackCollector;
00051 class ProxyFetchFactory;
00052 class RequestHeaders;
00053 class ResourceManager;
00054 class RewriteOptions;
00055 class Statistics;
00056 class TimedVariable;
00057 class Timer;
00058
00060 class ProxyInterface : public UrlAsyncFetcher {
00061 public:
00062 typedef std::pair<RewriteOptions*, bool> OptionsBoolPair;
00063
00064 ProxyInterface(const StringPiece& hostname, int port,
00065 ResourceManager* manager, Statistics* stats);
00066 virtual ~ProxyInterface();
00067
00069 static void Initialize(Statistics* statistics);
00070
00074 virtual bool Fetch(const GoogleString& requested_url,
00075 MessageHandler* handler,
00076 AsyncFetch* async_fetch);
00077
00086 OptionsBoolPair GetQueryOptions(GoogleUrl* request_url,
00087 RequestHeaders* request_headers,
00088 MessageHandler* handler);
00089
00093 RewriteOptions* GetCustomOptions(GoogleUrl* request_url,
00094 RequestHeaders* request_headers,
00095 RewriteOptions* domain_options,
00096 RewriteOptions* query_options,
00097 MessageHandler* handler);
00098
00099 void set_server_version(const StringPiece& server_version);
00100
00103 void ProxyRequestCallback(
00104 bool is_resource_fetch,
00105 GoogleUrl* request_url,
00106 AsyncFetch* async_fetch,
00107 RewriteOptions* domain_options,
00108 RewriteOptions* query_options,
00109 MessageHandler* handler);
00110
00111 static const char kBlinkRequestCount[];
00112 static const char kBlinkCriticalLineRequestCount[];
00113
00114 protected:
00116 virtual ProxyFetchPropertyCallbackCollector* InitiatePropertyCacheLookup(
00117 bool is_resource_fetch,
00118 const GoogleUrl& request_url,
00119 RewriteOptions* options,
00120 AsyncFetch* async_fetch);
00121
00122 private:
00123 friend class ProxyInterfaceTest;
00124
00128 void ProxyRequest(bool is_resource_fetch,
00129 const GoogleUrl& requested_url,
00130 AsyncFetch* async_fetch,
00131 MessageHandler* handler);
00132
00134 bool IsWellFormedUrl(const GoogleUrl& url);
00135
00138 bool UrlAndPortMatchThisServer(const GoogleUrl& url);
00139
00141 ResourceManager* resource_manager_;
00142 UrlAsyncFetcher* fetcher_;
00143 Timer* timer_;
00144 MessageHandler* handler_;
00145
00149 const GoogleString hostname_;
00150 const int port_;
00151
00154 TimedVariable* all_requests_;
00156 TimedVariable* pagespeed_requests_;
00158 TimedVariable* blink_requests_;
00160 TimedVariable* blink_critical_line_requests_;
00161
00162 scoped_ptr<ProxyFetchFactory> proxy_fetch_factory_;
00163
00164 DISALLOW_COPY_AND_ASSIGN(ProxyInterface);
00165 };
00166
00167 }
00168
00169 #endif ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_