Page Speed Optimization Libraries
1.13.35.1
|
#include "in_place_resource_recorder.h"
Public Types | |
enum | HeadersKind { kPreliminaryHeaders, kFullHeaders } |
Public Member Functions | |
InPlaceResourceRecorder (const RequestContextPtr &request_context, StringPiece url, StringPiece fragment, const RequestHeaders::Properties &request_properties, int max_response_bytes, int max_concurrent_recordings, 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 | SaveCacheControl (const char *cache_control) |
void | Fail () |
void | DoneAndSetHeaders (ResponseHeaders *response_headers, bool entire_response_received) |
const GoogleString & | url () const |
MessageHandler * | handler () |
bool | failed () |
bool | limit_active_recordings () |
const HttpOptions & | http_options () const |
Public Member Functions inherited from net_instaweb::Writer | |
virtual bool | Dump (Writer *writer, MessageHandler *message_handler) |
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, | ||
const RequestHeaders::Properties & | request_properties, | ||
int | max_response_bytes, | ||
int | max_concurrent_recordings, | ||
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 |
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:
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, |
bool | entire_response_received | ||
) |
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.
Set entire_response_received to true if you know that the response data fed into Write() is complete. For example, if the browser cancelled the download and so this is a partial response, set entire_response_received to false so we know not to cache it.
Does not take ownership of response_headers.
Deletes itself. Do not use object after calling DoneAndSetHeaders().
|
inline |
Call if something went wrong. The results will not be added to cache. You still need to call DoneAndSetHeaders().
|
inlinevirtual |
Flush is a no-op because we have to buffer up the whole contents before writing to cache.
Implements net_instaweb::Writer.
void net_instaweb::InPlaceResourceRecorder::SaveCacheControl | ( | const char * | cache_control | ) |
We modify the caching headers to add a short s-maxage on unoptimized resources, which includes when we're recording. We don't want to save the modified caching header to cache, though, so when doing that modification call SaveCacheControl with the existing value first.
If the response had no Cache-Control header, supply nullptr here and when we write out to the cache we won't include one. If Cache-Control is present but empty, supply the empty string and we'll write an empty header to cache.
Stores a copy of cache_control.
|
virtual |
These take a handler for compatibility with the Writer API, but the handler is not used.
Implements net_instaweb::Writer.