#include "mock_url_fetcher.h"
Classes | |
class | HttpResponse |
Public Member Functions | |
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 bool | StreamingFetchUrl (const GoogleString &url, const RequestHeaders &request_headers, ResponseHeaders *response_headers, Writer *response_writer, MessageHandler *message_handler) |
Fetching unset URLs will cause EXPECT failures as well as return false. | |
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 (MockTimer *timer) |
Simple UrlFetcher meant for tests, you can set responses for individual URLs. Meant only for testing.
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.
void net_instaweb::MockUrlFetcher::Disable | ( | ) | [inline] |
When disabled, fetcher will fail (but not crash) for all requests. Use to simulate temporarily not having access to resources, for example.
void net_instaweb::MockUrlFetcher::set_fail_after_headers | ( | bool | x | ) | [inline] |
If set to true (defaults to false) the fetcher will fail after outputting the headers. See also SetResponseFailure which fails after writing the body.
void net_instaweb::MockUrlFetcher::set_fail_on_unexpected | ( | bool | x | ) | [inline] |
Set to false if you don't want the fetcher to EXPECT fail on unfound URL. Useful in MockUrlFetcher unittest :)
void net_instaweb::MockUrlFetcher::set_omit_empty_writes | ( | bool | x | ) | [inline] |
If set to true (defaults to false) the fetcher will not emit writes of length 0.
void net_instaweb::MockUrlFetcher::set_update_date_headers | ( | bool | x | ) | [inline] |
Update response header's Date using supplied timer. Note: Must set_timer().
void net_instaweb::MockUrlFetcher::set_verify_host_header | ( | bool | x | ) | [inline] |
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.