Page Speed Optimization Libraries  1.7.30.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions
net_instaweb::MockUrlFetcher Class Reference

#include "mock_url_fetcher.h"

Inheritance diagram for net_instaweb::MockUrlFetcher:
net_instaweb::UrlAsyncFetcher

List of all members.

Classes

class  HttpResponse

Public Member Functions

 MockUrlFetcher ()
void SetResponse (const StringPiece &url, const ResponseHeaders &response_header, const StringPiece &response_body)
void AddToResponse (const StringPiece &url, const StringPiece &name, const StringPiece &value)
void SetConditionalResponse (const StringPiece &url, int64 last_modified_date, const GoogleString &etag, const ResponseHeaders &response_header, const StringPiece &response_body)
virtual void Fetch (const GoogleString &url, MessageHandler *message_handler, AsyncFetch *fetch)
 Fetching unset URLs will cause EXPECT failures as well as Done(false).
virtual bool SupportsHttps () const
void set_fetcher_supports_https (bool supports_https)
const GoogleString & last_referer ()
 Return the referer of this fetching request.
void SetResponseFailure (const StringPiece &url)
void Clear ()
 Clear all set responses.
void RemoveResponse (const StringPiece &url)
 Remove a single response. Will be a no-op if no response was set for url.
void Disable ()
void Enable ()
void set_fail_on_unexpected (bool x)
void set_update_date_headers (bool x)
void set_omit_empty_writes (bool x)
void set_fail_after_headers (bool x)
void set_verify_host_header (bool x)
void set_timer (Timer *timer)
void set_split_writes (bool val)
void set_error_message (const GoogleString &msg)
 If this is non-empty, we will write this out any time we report an error.

Detailed Description

Simple UrlFetcher meant for tests, you can set responses for individual URLs. Meant only for testing.


Constructor & Destructor Documentation

Todo:
TODO(hujie): We should pass in the mutex at all call-sites instead of creating a new mutex here.

Member Function Documentation

void net_instaweb::MockUrlFetcher::AddToResponse ( const StringPiece &  url,
const StringPiece &  name,
const StringPiece &  value 
)

Adds a new response-header attribute name/value pair to an existing response. If the response does not already exist, the method check-fails.

When disabled, fetcher will fail (but not crash) for all requests. Use to simulate temporarily not having access to resources, for example.

If set to true (defaults to false) the fetcher will fail after outputting the headers. See also SetResponseFailure which fails after writing the body.

Set to false if you don't want the fetcher to EXPECT fail on unfound URL. Useful in MockUrlFetcher unittest :)

If set to true (defaults to false) the fetcher will not emit writes of length 0.

If true then each time the fetcher writes it will split the write in half and write each half separately. This is needed to test that Ajax's RecordingFetch caches writes properly and recovers from failure.

Update response header's Date using supplied timer. Note: Must set_timer().

If set to true (defaults to false) the fetcher will verify that the Host: header is present, and matches the host/port of the requested URL.

void net_instaweb::MockUrlFetcher::SetConditionalResponse ( const StringPiece &  url,
int64  last_modified_date,
const GoogleString &  etag,
const ResponseHeaders &  response_header,
const StringPiece &  response_body 
)

Set a conditional response which will either respond with the supplied response_headers and response_body or a simple 304 Not Modified depending upon last_modified_time and conditional GET "If-Modified-Since" headers.

void net_instaweb::MockUrlFetcher::SetResponseFailure ( const StringPiece &  url)

Indicates that the specified URL should respond with headers and data, but still return a 'false' status. This is similar to a live fetcher that times out or disconnects while streaming data.

This differs from set_fail_after_headers in that it's specific to a URL, and writes the body first before returning failure.

virtual bool net_instaweb::MockUrlFetcher::SupportsHttps ( ) const [inline, virtual]

Determine if the fetcher supports fetching using HTTPS. By default we assume a fetcher can.

Reimplemented from net_instaweb::UrlAsyncFetcher.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines