Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::InPlaceResourceRecorder Class Reference

#include "in_place_resource_recorder.h"

Inheritance diagram for net_instaweb::InPlaceResourceRecorder:
net_instaweb::Writer

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 GoogleStringurl () const
 
MessageHandlerhandler ()
 
bool failed ()
 
bool limit_active_recordings ()
 
const HttpOptionshttp_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)
 

Detailed Description

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.

Member Enumeration Documentation

Enumerator
kPreliminaryHeaders 

Headers should only be used to determine if context was gzip'd by a reverse proxy.

kFullHeaders 

Headers are complete.

Constructor & Destructor Documentation

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 net_instaweb::InPlaceResourceRecorder::~InPlaceResourceRecorder ( )
virtual

Normally you should use DoneAndSetHeaders rather than deleting this directly.

Member Function Documentation

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,
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().

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)
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 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.

Implements net_instaweb::Writer.


The documentation for this class was generated from the following file: