Page Speed Optimization Libraries
1.8.31.3
|
#include "in_place_resource_recorder.h"
Classes | |
class | HTTPValueFetch |
Public Types | |
enum | HeadersKind { kPreliminaryHeaders, kFullHeaders } |
Public Member Functions | |
InPlaceResourceRecorder (const RequestContextPtr &request_context, StringPiece url, StringPiece fragment, RequestHeaders::Properties request_properties, bool respect_vary, int max_response_bytes, int max_concurrent_recordings, int64 implicit_cache_ttl_ms, HTTPCache *cache, Statistics *statistics, MessageHandler *handler) | |
virtual | ~InPlaceResourceRecorder () |
virtual bool | Write (const StringPiece &contents, MessageHandler *handler) |
virtual bool | Flush (MessageHandler *handler) |
void | ConsiderResponseHeaders (HeadersKind headers_kind, ResponseHeaders *response_headers) |
void | Fail () |
void | DoneAndSetHeaders (ResponseHeaders *response_headers) |
const GoogleString & | url () const |
MessageHandler * | handler () |
bool | failed () |
bool | limit_active_recordings () |
int64 | implicit_cache_ttl_ms () |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
Records a copy of a resource streamed through it and saves the result to the cache if it's cacheable. Used in the In-Place Resource Optimization (IPRO) flow to get resources into the cache.
net_instaweb::InPlaceResourceRecorder::InPlaceResourceRecorder | ( | const RequestContextPtr & | request_context, |
StringPiece | url, | ||
StringPiece | fragment, | ||
RequestHeaders::Properties | request_properties, | ||
bool | respect_vary, | ||
int | max_response_bytes, | ||
int | max_concurrent_recordings, | ||
int64 | implicit_cache_ttl_ms, | ||
HTTPCache * | cache, | ||
Statistics * | statistics, | ||
MessageHandler * | handler | ||
) |
Does not take ownership of request_headers, cache nor handler. Like other callbacks, InPlaceResourceRecorder is self-owned and will delete itself when DoneAndSetHeaders() is called.
virtual net_instaweb::InPlaceResourceRecorder::~InPlaceResourceRecorder | ( | ) | [virtual] |
Normally you should use DoneAndSetHeaders rather than deleting this directly.
void net_instaweb::InPlaceResourceRecorder::ConsiderResponseHeaders | ( | HeadersKind | headers_kind, |
ResponseHeaders * | response_headers | ||
) |
Sometimes the response headers prohibit IPRO: If it's not an IPRO content type. If it's not served as cacheable. If there's a content length, and it's over our max. In these cases, shift into the failed state and stop any resource recording.
At this time we might also realize that there are too many IPRO recordings going on and skip IPRO for that reason. In that case we don't mark the resource as not ipro-cacheable.
You must call ConsiderResponseHeaders() with whatever information is available before payload. If it's only enough to determine if content is gzip'ed, pass in kPreliminaryHeaders. If it's the complete final headers, pass in kFullHeaders.
Call DoneAndSetHeaders() after the entire payload and headers are available. Note that only Content-Encoding: from ConsiderResponseHeaders will be used to determine whether to gunzip content or not. This is done since in Apache we can only capture the full headers after mod_deflate has already run, while content is captured before.
Does not take ownership of response_headers.
void net_instaweb::InPlaceResourceRecorder::DoneAndSetHeaders | ( | ResponseHeaders * | response_headers | ) |
Call when finished and the final response headers are known. Because of Apache's quirky filter order, we cannot get both the uncompressed final contents and the complete headers at the same time.
Does not take ownership of response_headers.
Deletes itself. Do not use object after calling DoneAndSetHeaders().
void net_instaweb::InPlaceResourceRecorder::Fail | ( | ) | [inline] |
Call if something went wrong. The results will not be added to cache. You still need to call DoneAndSetHeaders().
virtual bool net_instaweb::InPlaceResourceRecorder::Flush | ( | MessageHandler * | handler | ) | [inline, virtual] |
Flush is a no-op because we have to buffer up the whole contents before writing to cache.
virtual bool net_instaweb::InPlaceResourceRecorder::Write | ( | const StringPiece & | contents, |
MessageHandler * | handler | ||
) | [virtual] |
These take a handler for compatibility with the Writer API, but the handler is not used.