22 #ifndef NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_H_
23 #define NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_H_
26 #include "net/instaweb/http/public/request_context.h"
35 namespace net_instaweb {
37 class AbstractLogRecord;
55 static const int kContentLengthUnknown = -1;
72 void Done(
bool success);
129 virtual void Reset() { headers_complete_ =
false; }
131 bool headers_complete()
const {
return headers_complete_; }
140 return content_length_ != kContentLengthUnknown;
142 int64 content_length()
const {
return content_length_; }
143 void set_content_length(int64 x) { content_length_ = x; }
169 virtual bool HandleWrite(
const StringPiece& sp,
MessageHandler* handler) = 0;
171 virtual void HandleDone(
bool success) = 0;
172 virtual void HandleHeadersComplete() = 0;
179 bool owns_request_headers_;
180 bool owns_response_headers_;
181 bool owns_extra_response_headers_;
182 bool headers_complete_;
183 int64 content_length_;
195 :
AsyncFetch(request_ctx), buffer_pointer_(&buffer_) {
200 :
AsyncFetch(request_ctx), buffer_pointer_(buffer) {
206 virtual bool HandleWrite(
const StringPiece& content,
208 content.AppendToString(buffer_pointer_);
211 virtual bool HandleFlush(
MessageHandler* handler) {
return true; }
212 virtual void HandleHeadersComplete() {}
213 virtual void HandleDone(
bool success) {
218 bool success()
const {
return success_; }
219 bool done()
const {
return done_; }
220 const GoogleString& buffer()
const {
return *buffer_pointer_; }
225 buffer_pointer_->clear();
236 void set_done(
bool done) { done_ = done; }
264 virtual bool HandleWrite(
const StringPiece& sp,
MessageHandler* handler);
288 virtual void HandleDone(
bool success) {
289 base_fetch_->
Done(success);
292 virtual bool HandleWrite(
const StringPiece& content,
293 MessageHandler* handler) {
294 return base_fetch_->
Write(content, handler);
297 virtual bool HandleFlush(MessageHandler* handler) {
298 return base_fetch_->Flush(handler);
301 virtual void HandleHeadersComplete();
333 void set_fallback_responses_served(
Variable* x) {
334 fallback_responses_served_ = x;
337 bool serving_fallback()
const {
return serving_fallback_; }
340 virtual void HandleDone(
bool success);
341 virtual bool HandleWrite(
const StringPiece& content, MessageHandler* handler);
342 virtual bool HandleFlush(MessageHandler* handler);
343 virtual void HandleHeadersComplete();
347 MessageHandler* handler_;
349 bool serving_fallback_;
350 Variable* fallback_responses_served_;
370 void set_num_conditional_refreshes(
Variable* x) {
371 num_conditional_refreshes_ = x;
375 virtual void HandleDone(
bool success);
376 virtual bool HandleWrite(
const StringPiece& content,
MessageHandler* handler);
378 virtual void HandleHeadersComplete();
386 bool serving_cached_value_;
388 bool added_conditional_headers_to_request_;
390 Variable* num_conditional_refreshes_;
void FixCacheControlForGoogleCache()
Definition: http_value.h:38
void set_success(bool success)
Definition: async_fetch.h:235
Definition: statistics.h:43
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:151
ResponseHeaders * response_headers()
See doc for request_headers and set_request_headers.
Definition: log_record.h:59
virtual bool IsBackgroundFetch() const
Definition: async_fetch.h:307
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:283
GoogleString LoggingString()
RequestHeaders * request_headers()
void SetRequestHeadersTakingOwnership(RequestHeaders *headers)
Same as above, but takes ownership.
static const char kStaleWarningHeaderValue[]
Warning header to be added if a stale response is served.
Definition: async_fetch.h:327
virtual AbstractLogRecord * log_record()
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static bool IsGoogleCacheVia(StringPiece via_value)
virtual void Reset()
Definition: async_fetch.h:222
Definition: async_fetch.h:278
Definition: async_fetch.h:53
Definition: async_fetch.h:364
void PropagateContentLength()
Propagates any set_content_length from this to the base fetch.
virtual bool IsCachedResultValid(const ResponseHeaders &headers)
Definition: async_fetch.h:303
Interface for writing bytes to an output stream.
Definition: writer.h:29
virtual bool IsBackgroundFetch() const
Definition: async_fetch.h:125
Definition: async_fetch.h:255
ResponseHeaders * extra_response_headers()
Definition: message_handler.h:39
Definition: async_fetch.h:324
virtual bool IsCachedResultValid(const ResponseHeaders &headers)
Definition: async_fetch.h:85
Definition: async_fetch.h:192
virtual bool Write(const StringPiece &content, MessageHandler *handler)
void set_request_headers(RequestHeaders *headers)
bool content_length_known() const
Definition: async_fetch.h:139
virtual void Reset()
Definition: async_fetch.h:129