19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_REQUEST_CONTEXT_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_REQUEST_CONTEXT_H_
24 #include "base/logging.h"
25 #include "pagespeed/kernel/base/basictypes.h"
26 #include "pagespeed/kernel/base/ref_counted_ptr.h"
27 #include "pagespeed/kernel/base/scoped_ptr.h"
28 #include "pagespeed/kernel/base/string.h"
29 #include "pagespeed/kernel/base/string_util.h"
30 #include "pagespeed/kernel/http/http_options.h"
32 namespace net_instaweb {
34 class AbstractLogRecord;
41 typedef RefCountedPtr<RequestContext> RequestContextPtr;
64 RequestContext(
const HttpOptions& options, AbstractMutex* logging_mutex,
73 return NewTestRequestContextWithTimer(thread_system, NULL);
75 static RequestContextPtr NewTestRequestContextWithTimer(
76 ThreadSystem* thread_system, Timer* timer);
83 AbstractMutex* logging_mutex);
125 void set_using_spdy(
bool x) { using_spdy_ = x; }
140 return minimal_private_suffix_;
143 minimal_private_suffix.CopyToString(&minimal_private_suffix_);
149 bool accepts_webp()
const {
return accepts_webp_; }
153 return split_request_type_;
156 split_request_type_ = type;
159 int64 request_id()
const {
162 void set_request_id(int64 x) {
166 const GoogleString& sticky_query_parameters_token()
const {
167 return sticky_query_parameters_token_;
169 void set_sticky_query_parameters_token(StringPiece x) {
170 x.CopyToString(&sticky_query_parameters_token_);
180 void AddSessionAuthorizedFetchOrigin(
const GoogleString& origin) {
181 session_authorized_fetch_origins_.insert(origin);
187 return session_authorized_fetch_origins_.find(origin)
188 != session_authorized_fetch_origins_.end();
202 ThreadSystem* thread_system,
204 bool log_url_indices,
205 int max_rewrite_info_log_size);
226 TimingInfo(Timer* timer, AbstractMutex* mutex);
245 SetToNow(&pcache_lookup_start_ts_ms_);
261 void FetchHeaderReceived();
262 void FetchFinished();
267 void SetL2HTTPCacheLatencyMs(int64 latency_ms);
274 return GetTimeFromStart(processing_start_ts_ms_, elapsed_ms);
285 return GetTimeFromStart(pcache_lookup_start_ts_ms_, elapsed_ms);
290 return GetTimeFromStart(pcache_lookup_end_ts_ms_, elapsed_ms);
295 bool GetL2HTTPCacheLatencyMs(int64* latency_ms)
const;
312 return GetTimeFromStart(parsing_start_ts_ms_, elapsed_ms);
315 int64 init_ts_ms()
const {
return init_ts_ms_; }
317 int64 start_ts_ms()
const {
return start_ts_ms_; }
323 void SetToNow(int64* ts_ms)
const;
327 bool GetTimeFromStart(int64 ts_ms, int64* elapsed_ms)
const;
339 int64 processing_start_ts_ms_;
340 int64 pcache_lookup_start_ts_ms_;
341 int64 pcache_lookup_end_ts_ms_;
342 int64 parsing_start_ts_ms_;
346 int64 fetch_start_ts_ms_;
348 int64 fetch_header_ts_ms_;
349 int64 fetch_end_ts_ms_;
350 int64 first_byte_ts_ms_;
353 int64 http_cache_latency_ms_;
354 int64 l2http_cache_latency_ms_;
359 const TimingInfo& timing_info()
const {
return timing_info_; }
360 TimingInfo* mutable_timing_info() {
return &timing_info_; }
362 void set_options(
const HttpOptions& options) {
363 DCHECK(!options_set_);
374 const HttpOptions& options()
const {
375 DCHECK(options_set_);
391 scoped_ptr<AbstractLogRecord> log_record_;
393 TimingInfo timing_info_;
396 scoped_ptr<RequestTrace> root_trace_context_;
399 scoped_ptr<AbstractLogRecord> background_rewrite_log_record_;
401 StringSet session_authorized_fetch_origins_;
405 GoogleString minimal_private_suffix_;
412 GoogleString sticky_query_parameters_token_;
415 HttpOptions options_;
Definition: request_context.h:221
SplitRequestType
Types of split html request.
Definition: request_context.h:53
void PrepareLogRecordForOutput()
void RequestFinished()
Definition: request_context.h:253
const GoogleString & minimal_private_suffix() const
Definition: request_context.h:139
Definition: request_context.h:50
void SetHTTPCacheLatencyMs(int64 latency_ms)
bool GetTimeToFirstByte(int64 *latency_ms) const
bool GetHTTPCacheLatencyMs(int64 *latency_ms) const
HTTP Cache latencies.
void set_accepts_webp(bool x)
Definition: request_context.h:148
virtual ~RequestContext()
Destructors in refcounted classes should be protected.
Definition: log_record.h:61
int64 GetElapsedMs() const
Milliseconds since Init.
bool using_spdy() const
Determines whether this request is using the SPDY protocol.
Definition: request_context.h:124
bool GetTimeToStartProcessingMs(int64 *elapsed_ms) const
Milliseconds from request start to processing start.
Definition: request_context.h:273
void ProcessingStarted()
Definition: request_context.h:235
TimingInfo(Timer *timer, AbstractMutex *mutex)
bool GetProcessingElapsedMs(int64 *elapsed_ms) const
bool GetTimeToStartParseMs(int64 *elapsed_ms) const
Milliseconds from request start to parse start.
Definition: request_context.h:311
virtual RequestTrace * CreateDependentTraceContext(const StringPiece &label)
Definition: request_context.h:103
void ParsingStarted()
This should be called if/when HTML parsing begins.
Definition: request_context.h:238
virtual AbstractLogRecord * log_record()
The log record for the this request, created when the request context is.
virtual void ReleaseDependentTraceContext(RequestTrace *t)
void PropertyCacheLookupStarted()
This should be called when a PropertyCache lookup is initiated.
Definition: request_context.h:244
static RequestContextPtr NewTestRequestContext(ThreadSystem *thread_system)
Definition: request_context.h:72
RequestContext(const HttpOptions &options, AbstractMutex *logging_mutex, Timer *timer)
void set_root_trace_context(RequestTrace *x)
Takes ownership of the given context.
bool GetTimeToStartFetchMs(int64 *elapsed_ms) const
Milliseconds from request start to fetch start.
RequestTrace * root_trace_context()
Definition: request_context.h:89
void WriteBackgroundRewriteLog()
Write the log for background rewriting into disk.
void PropertyCacheLookupFinished()
This should be called when a PropertyCache lookup completes.
Definition: request_context.h:249
bool GetFetchHeaderLatencyMs(int64 *latency_ms) const
Milliseconds from fetch start to header received.
bool GetFetchLatencyMs(int64 *latency_ms) const
Milliseconds from fetch start to fetch end.
bool GetTimeToPropertyCacheLookupEndMs(int64 *elapsed_ms) const
Milliseconds from request start to pcache lookup end.
Definition: request_context.h:289
virtual AbstractLogRecord * NewSubordinateLogRecord(AbstractMutex *logging_mutex)
bool GetTimeToPropertyCacheLookupStartMs(int64 *elapsed_ms) const
Milliseconds from request start to pcache lookup start.
Definition: request_context.h:284
bool IsSessionAuthorizedFetchOrigin(const GoogleString &origin) const
Definition: request_context.h:186
SplitRequestType split_request_type() const
Indicates the type of split html request.
Definition: request_context.h:152
void ResetOptions(const HttpOptions &options)
Definition: request_context.h:370
AbstractLogRecord * GetBackgroundRewriteLog(ThreadSystem *thread_system, bool log_urls, bool log_url_indices, int max_rewrite_info_log_size)
void FirstByteReturned()
Called when the first byte is sent back to the user.