~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/automatic/public/proxy_interface.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Google Inc.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
// Author: sligocki@google.com (Shawn Ligocki)
18
 
//
19
 
// Simple interface for running Page Speed Automatic as a proxy.
20
 
//
21
 
// When implementing a Page Speed Automatic proxy, simply construct a
22
 
// ProxyInterface at start up time and call Fetch for every
23
 
// requested resource. Fetch decides how to deal with requests
24
 
// (pagespeed resources will be computed, HTML pages will be proxied
25
 
// and rewritten, and other resources will just be proxied).
26
 
 
27
 
#ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
28
 
#define NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
29
 
 
30
 
#include "net/instaweb/http/public/url_async_fetcher.h"
31
 
#include "net/instaweb/util/public/basictypes.h"
32
 
#include "net/instaweb/util/public/scoped_ptr.h"
33
 
#include "net/instaweb/util/public/string.h"
34
 
#include "net/instaweb/util/public/string_util.h"
35
 
 
36
 
namespace net_instaweb {
37
 
 
38
 
class AsyncFetch;
39
 
class GoogleUrl;
40
 
class MessageHandler;
41
 
class ProxyFetchPropertyCallbackCollector;
42
 
class ProxyFetchFactory;
43
 
class ServerContext;
44
 
class RewriteOptions;
45
 
class Statistics;
46
 
class TimedVariable;
47
 
 
48
 
// TODO(sligocki): Rename as per style-guide.
49
 
class ProxyInterface : public UrlAsyncFetcher {
50
 
 public:
51
 
  ProxyInterface(const StringPiece& hostname, int port,
52
 
                 ServerContext* server_context, Statistics* stats);
53
 
  virtual ~ProxyInterface();
54
 
 
55
 
  // Initializes statistics variables associated with this class.
56
 
  static void InitStats(Statistics* statistics);
57
 
 
58
 
  // All requests use this interface. We decide internally whether the
59
 
  // request is a pagespeed resource, HTML page to be rewritten or another
60
 
  // resource to be proxied directly.
61
 
  virtual void Fetch(const GoogleString& requested_url,
62
 
                     MessageHandler* handler,
63
 
                     AsyncFetch* async_fetch);
64
 
 
65
 
  // Is this url_string well-formed enough to proxy through?
66
 
  bool IsWellFormedUrl(const GoogleUrl& url);
67
 
 
68
 
  static const char kCacheHtmlRequestCount[];
69
 
 
70
 
  // Initiates the PropertyCache look up.
71
 
  virtual ProxyFetchPropertyCallbackCollector* InitiatePropertyCacheLookup(
72
 
      bool is_resource_fetch,
73
 
      const GoogleUrl& request_url,
74
 
      RewriteOptions* options,
75
 
      AsyncFetch* async_fetch,
76
 
      const bool requires_blink_cohort,
77
 
      bool* added_page_property_callback);
78
 
 
79
 
 protected:
80
 
  // Needed by subclasses when overriding InitiatePropertyCacheLookup.
81
 
  ServerContext* server_context_;  // thread-safe, unowned
82
 
 
83
 
 private:
84
 
  friend class ProxyInterfaceTest;
85
 
 
86
 
  // Handle requests that are being proxied.
87
 
  // * HTML requests are rewritten.
88
 
  // * Resource requests are proxied verbatim.
89
 
  void ProxyRequest(bool is_resource_fetch,
90
 
                    const GoogleUrl& requested_url,
91
 
                    AsyncFetch* async_fetch,
92
 
                    MessageHandler* handler);
93
 
 
94
 
  // Callback function which runs once we have rewrite_options for requests that
95
 
  // are being proxied.
96
 
  struct RequestData;
97
 
  void GetRewriteOptionsDone(RequestData* request_data,
98
 
                             RewriteOptions* query_options);
99
 
 
100
 
  // If the URL and port are for this server, don't proxy those (to avoid
101
 
  // infinite fetching loops). This might be the favicon or something...
102
 
  bool UrlAndPortMatchThisServer(const GoogleUrl& url);
103
 
 
104
 
  // This server's hostname and port (to avoid making circular requests).
105
 
  // TODO(sligocki): This assumes we will only be called as one hostname,
106
 
  // there could be multiple DNS entries pointing at us.
107
 
  const GoogleString hostname_;
108
 
  const int port_;
109
 
 
110
 
  // Varz variables
111
 
  // Total requests.
112
 
  TimedVariable* all_requests_;
113
 
  // Total Pagespeed requests.
114
 
  TimedVariable* pagespeed_requests_;
115
 
  // Cache Html requests.
116
 
  TimedVariable* cache_html_flow_requests_;
117
 
  // Rejected requests counter.
118
 
  TimedVariable* rejected_requests_;
119
 
 
120
 
  scoped_ptr<ProxyFetchFactory> proxy_fetch_factory_;
121
 
 
122
 
  DISALLOW_COPY_AND_ASSIGN(ProxyInterface);
123
 
};
124
 
 
125
 
}  // namespace net_instaweb
126
 
 
127
 
#endif  // NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_