Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
request_context.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 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 
18 
19 #ifndef PAGESPEED_OPT_HTTP_REQUEST_CONTEXT_H_
20 #define PAGESPEED_OPT_HTTP_REQUEST_CONTEXT_H_
21 
22 #include <set>
23 
24 #include "base/logging.h"
32 
33 namespace net_instaweb {
34 
35 class AbstractLogRecord;
36 class AbstractMutex;
37 class RequestContext;
38 class RequestTrace;
39 class ThreadSystem;
40 class Timer;
41 
42 typedef RefCountedPtr<RequestContext> RequestContextPtr;
43 
51 class RequestContext : public RefCounted<RequestContext> {
52  public:
58  RequestContext(const HttpOptions& options, AbstractMutex* logging_mutex,
59  Timer* timer);
61  RequestContext(AbstractMutex* logging_mutex, Timer* timer);
62 
67  return NewTestRequestContextWithTimer(thread_system, NULL);
68  }
69  static RequestContextPtr NewTestRequestContextWithTimer(
70  ThreadSystem* thread_system, Timer* timer);
72 
77  AbstractMutex* logging_mutex);
78 
83  RequestTrace* root_trace_context() { return root_trace_context_.get(); }
86 
97  virtual RequestTrace* CreateDependentTraceContext(const StringPiece& label) {
98  return NULL;
99  }
100 
113 
115  virtual AbstractLogRecord* log_record();
116 
118  bool using_http2() const { return using_http2_; }
119  void set_using_http2(bool x) { using_http2_ = x; }
120 
128  void SetHttp2SupportFromViaHeader(StringPiece header);
129 
143  return minimal_private_suffix_;
144  }
145  void set_minimal_private_suffix(StringPiece minimal_private_suffix) {
146  minimal_private_suffix.CopyToString(&minimal_private_suffix_);
147  }
148 
151  void SetAcceptsWebp(bool x);
152  bool accepts_webp() const { return accepts_webp_; }
153 
156  void SetAcceptsGzip(bool x);
157  bool accepts_gzip() const { return accepts_gzip_; }
158 
159  int64 request_id() const {
160  return request_id_;
161  }
162  void set_request_id(int64 x) {
163  request_id_ = x;
164  }
165 
166  const GoogleString& sticky_query_parameters_token() const {
167  return sticky_query_parameters_token_;
168  }
169  void set_sticky_query_parameters_token(StringPiece x) {
170  x.CopyToString(&sticky_query_parameters_token_);
171  }
172 
180  void AddSessionAuthorizedFetchOrigin(const GoogleString& origin) {
181  session_authorized_fetch_origins_.insert(origin);
182  }
183 
186  bool IsSessionAuthorizedFetchOrigin(const GoogleString& origin) const {
187  return session_authorized_fetch_origins_.find(origin)
188  != session_authorized_fetch_origins_.end();
189  }
190 
195 
198 
202  ThreadSystem* thread_system,
203  bool log_urls,
204  bool log_url_indices,
205  int max_rewrite_info_log_size);
206 
207  const RequestTimingInfo& timing_info() const { return timing_info_; }
208  RequestTimingInfo* mutable_timing_info() { return &timing_info_; }
209 
210  void set_options(const HttpOptions& options) {
211  DCHECK(!options_set_);
212  options_set_ = true;
213  options_ = options;
214  }
218  void ResetOptions(const HttpOptions& options) {
219  options_set_ = true;
220  options_ = options;
221  }
222  const HttpOptions& options() const {
223  DCHECK(options_set_);
224  return options_;
225  }
226 
227  void Freeze() { frozen_ = true; }
228  bool frozen() const { return frozen_; }
229 
230  protected:
234  RequestContext(const HttpOptions& options, AbstractMutex* mutex,
235  Timer* timer, AbstractLogRecord* log_record);
237  virtual ~RequestContext();
238  REFCOUNT_FRIEND_DECLARATION(RequestContext);
239 
240  private:
241  void Init();
242 
244  scoped_ptr<AbstractLogRecord> log_record_;
245 
246  RequestTimingInfo timing_info_;
247 
249  scoped_ptr<RequestTrace> root_trace_context_;
250 
252  scoped_ptr<AbstractLogRecord> background_rewrite_log_record_;
253 
254  StringSet session_authorized_fetch_origins_;
255 
256  bool using_http2_;
257  bool accepts_webp_;
258  bool accepts_gzip_;
259  bool frozen_;
260  GoogleString minimal_private_suffix_;
261 
262  int64 request_id_;
263 
266  GoogleString sticky_query_parameters_token_;
267 
268  bool options_set_;
269  HttpOptions options_;
270 
271 
272 };
273 
274 }
275 
276 #endif
const GoogleString & minimal_private_suffix() const
Definition: request_context.h:142
Definition: request_context.h:51
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
virtual ~RequestContext()
Destructors in refcounted classes should be protected.
Definition: ref_counted_ptr.h:41
Definition: log_record.h:59
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: request_timing_info.h:43
virtual RequestTrace * CreateDependentTraceContext(const StringPiece &label)
Definition: request_context.h:97
virtual AbstractLogRecord * log_record()
The log record for the this request, created when the request context is.
void SetHttp2SupportFromViaHeader(StringPiece header)
virtual void ReleaseDependentTraceContext(RequestTrace *t)
static RequestContextPtr NewTestRequestContext(ThreadSystem *thread_system)
Definition: request_context.h:66
RequestContext(const HttpOptions &options, AbstractMutex *logging_mutex, Timer *timer)
void set_root_trace_context(RequestTrace *x)
Takes ownership of the given context.
RequestTrace * root_trace_context()
Definition: request_context.h:83
Definition: thread_system.h:40
void WriteBackgroundRewriteLog()
Write the log for background rewriting into disk.
Definition: request_trace.h:31
virtual AbstractLogRecord * NewSubordinateLogRecord(AbstractMutex *logging_mutex)
Any options which need to be accessed in http/ should be in here.
Definition: http_options.h:25
bool using_http2() const
Determines whether this request is using the HTTP2 protocol.
Definition: request_context.h:118
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
bool IsSessionAuthorizedFetchOrigin(const GoogleString &origin) const
Definition: request_context.h:186
void ResetOptions(const HttpOptions &options)
Definition: request_context.h:218
AbstractLogRecord * GetBackgroundRewriteLog(ThreadSystem *thread_system, bool log_urls, bool log_url_indices, int max_rewrite_info_log_size)