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

#include "async_fetch.h"

Inheritance diagram for net_instaweb::AsyncFetch:
net_instaweb::Writer net_instaweb::ApacheFetch net_instaweb::AsyncFetchUsingWriter net_instaweb::AsyncFetchWithLock net_instaweb::NotifyingFetch net_instaweb::SharedAsyncFetch net_instaweb::SimpleBufferedApacheFetch net_instaweb::StringAsyncFetch net_instaweb::SyncFetcherAdapterCallback

Public Member Functions

 AsyncFetch (const RequestContextPtr &request_ctx)
 
void HeadersComplete ()
 
void Done (bool success)
 
virtual bool Write (const StringPiece &content, MessageHandler *handler)
 
virtual bool Flush (MessageHandler *handler)
 
virtual bool IsCachedResultValid (const ResponseHeaders &headers)
 
RequestHeadersrequest_headers ()
 
void set_request_headers (RequestHeaders *headers)
 
void SetRequestHeadersTakingOwnership (RequestHeaders *headers)
 Same as above, but takes ownership.
 
const RequestHeadersrequest_headers () const
 
ResponseHeadersresponse_headers ()
 See doc for request_headers and set_request_headers.
 
void set_response_headers (ResponseHeaders *headers)
 
ResponseHeadersextra_response_headers ()
 
void set_extra_response_headers (ResponseHeaders *headers)
 
virtual bool IsBackgroundFetch () const
 
virtual void Reset ()
 
bool headers_complete () const
 
bool content_length_known () const
 
int64 content_length () const
 
void set_content_length (int64 x)
 
GoogleString LoggingString ()
 
virtual const RequestContextPtrrequest_context ()
 
virtual AbstractLogRecordlog_record ()
 
void FixCacheControlForGoogleCache ()
 
- Public Member Functions inherited from net_instaweb::Writer
virtual bool Dump (Writer *writer, MessageHandler *message_handler)
 

Static Public Member Functions

static bool IsGoogleCacheVia (StringPiece via_value)
 

Static Public Attributes

static const int kContentLengthUnknown = -1
 

Protected Member Functions

virtual bool HandleWrite (const StringPiece &sp, MessageHandler *handler)=0
 
virtual bool HandleFlush (MessageHandler *handler)=0
 
virtual void HandleDone (bool success)=0
 
virtual void HandleHeadersComplete ()=0
 

Detailed Description

Abstract base class for encapsulating streaming, asynchronous HTTP fetches.

If you want to fetch a resources, implement this interface, create an instance and call UrlAsyncFetcher::Fetch() with it.

It combines the 3 callbacks we expect to get from fetchers (Write, Flush and Done) and adds a HeadersComplete indicator that is useful in any place where we want to deal with and send headers before Write or Done are called.

Note that it automatically invokes HeadersComplete before the first call to Write, Flush or Done.

Member Function Documentation

bool net_instaweb::AsyncFetch::content_length_known ( ) const
inline

Keep track of whether the content-length is known before the body is sent, so that a server can decide whether it needs chunked.

Note that this is not necessarily the same as the Content-Length attribute in the response-headers, which might reflect pre-optimized or pre-compressed sizes.

void net_instaweb::AsyncFetch::Done ( bool  success)

Fetch complete. This interface is intended for callers (e.g. Fetchers). Implementors must override HandleDone.

ResponseHeaders* net_instaweb::AsyncFetch::extra_response_headers ( )

Returns extra response headers which may be modified between calls to HeadersComplete() and Done(). This is used to allow a fetch to provide additional headers which cannot be determined when HeadersComplete() has been invoked, e.g., X-Original-Content-Length. This is needed because it is not safe for the producer to modify response_headers() once HeadersComplete() has been called.

void net_instaweb::AsyncFetch::FixCacheControlForGoogleCache ( )

Determines whether the specified request-headers imply that the server is running in a context where an explicit cache-control "public" header is needed to make caching work, and adds that header if needed.

void net_instaweb::AsyncFetch::HeadersComplete ( )

Called when ResponseHeaders have been set, but before writing contents. Contract: Must be called (at most once) before Write, Flush or Done. Automatically invoked (if neccessary) before the first call to Write, Flush, or Done. This interface is intended for callers (e.g. Fetchers). Implementors of the AsyncFetch interface must override HandleHeadersComplete.

virtual bool net_instaweb::AsyncFetch::IsBackgroundFetch ( ) const
inlinevirtual

Indicates whether the request is a background fetch. These can be scheduled differently by the fetcher.

Reimplemented in net_instaweb::SharedAsyncFetch.

virtual bool net_instaweb::AsyncFetch::IsCachedResultValid ( const ResponseHeaders headers)
inlinevirtual

Is the cache entry corresponding to headers valid? Default is that it is valid. Sub-classes can provide specific implementations, e.g., based on cache invalidation timestamp in domain specific options. Used by CacheUrlAsyncFetcher.

Todo:
TODO(nikhilmadan): Consider making this virtual so that subclass authors are forced to look at this function.

Reimplemented in net_instaweb::ProxyFetch, net_instaweb::SharedAsyncFetch, net_instaweb::ApacheFetch, net_instaweb::SimpleBufferedApacheFetch, and net_instaweb::NotifyingFetch.

static bool net_instaweb::AsyncFetch::IsGoogleCacheVia ( StringPiece  via_value)
static

Determines whether the specified via header value matches the expected pattern for the Via header provided by the Google Cloud CDN to services running inside it.

virtual AbstractLogRecord* net_instaweb::AsyncFetch::log_record ( )
virtual

Returns a pointer to a log record that wraps this fetch's logging info.

GoogleString net_instaweb::AsyncFetch::LoggingString ( )

Returns logging information in a string eg. c1:0;c2:2;hf:45;. c1 is cache 1, c2 is cache 2, hf is headers fetch.

virtual const RequestContextPtr& net_instaweb::AsyncFetch::request_context ( )
inlinevirtual

Returns the request context associated with this fetch, if any, or NULL if no request context exists.

Reimplemented in net_instaweb::SharedAsyncFetch.

RequestHeaders* net_instaweb::AsyncFetch::request_headers ( )

Returns a pointer to the request-headers, lazily constructing them if needed. If they are constructed here (as opposed to being set with set_request_headers) then they will be owned by the class instance.

const RequestHeaders* net_instaweb::AsyncFetch::request_headers ( ) const

Returns the request_headers as a const pointer: it is required that the RequestHeaders be pre-initialized via non-const request_headers() or via set_request_headers before calling this.

virtual void net_instaweb::AsyncFetch::Reset ( )
inlinevirtual

Resets the 'headers_complete_' flag.

Todo:
TODO(jmarantz): should this also clear the response headers?

Reimplemented in net_instaweb::StringAsyncFetch, and net_instaweb::InflatingFetch.

void net_instaweb::AsyncFetch::set_request_headers ( RequestHeaders headers)

Sets the request-headers to the specifid pointer. The caller must guarantee that the pointed-to headers remain valid as long as the AsyncFetch is running.

Does not take ownership of headers.

virtual bool net_instaweb::AsyncFetch::Write ( const StringPiece &  content,
MessageHandler handler 
)
virtual

Data available. This interface is intended for callers. Implementors must override HandlerWrite and HandleFlush.

Implements net_instaweb::Writer.


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