26 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_H_
27 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_H_
31 #include "base/logging.h"
34 #include "net/instaweb/http/public/request_context.h"
44 namespace net_instaweb {
54 typedef RefCountedPtr<Resource> ResourcePtr;
55 typedef std::vector<ResourcePtr> ResourceVector;
69 kLoadEvenIfNotCacheable,
70 kReportFailureIfNotCacheable,
87 void set_is_authorized_domain(
bool is_authorized) {
88 is_authorized_domain_ = is_authorized;
105 bool loaded()
const {
return response_headers_.status_code() != 0; }
106 bool HttpStatusOk()
const {
107 return (response_headers_.status_code() == HttpStatus::kOK);
119 const RequestContextPtr& request_context,
120 AsyncCallback* callback);
139 int index, CachedResult* partition);
154 void FillInPartitionInputInfoFromResponseHeaders(
155 const ResponseHeaders& headers,
176 StringPiece raw_contents()
const {
179 CHECK(got_contents) <<
"Resource contents read before loading: "
184 ResponseHeaders* response_headers() {
return &response_headers_; }
185 const ResponseHeaders* response_headers()
const {
return &response_headers_; }
186 const ContentType* type()
const {
return type_; }
187 virtual void SetType(
const ContentType* type);
188 bool IsContentsEmpty()
const {
189 return raw_contents().empty();
193 StringPiece
charset()
const {
return charset_; }
194 void set_charset(StringPiece c) { c.CopyToString(&charset_); }
222 virtual void Done(
bool lock_failure,
bool resource_ok) = 0;
224 const ResourcePtr& resource() {
return resource_; }
245 virtual void Done(
bool lock_failure,
bool resource_ok) {
268 void set_is_background_fetch(
bool x) { is_background_fetch_ = x; }
269 bool is_background_fetch()
const {
return is_background_fetch_; }
272 return fetch_response_status_;
276 fetch_response_status_ = x;
286 REFCOUNT_FRIEND_DECLARATION(Resource);
287 friend class ServerContext;
290 friend class UrlReadAsyncFetchCallback;
305 void set_enable_cache_purge(
bool x) { enable_cache_purge_ = x; }
306 ResponseHeaders::VaryOption respect_vary()
const {
return respect_vary_; }
307 void set_respect_vary(ResponseHeaders::VaryOption x) { respect_vary_ = x; }
308 void set_proactive_resource_freshening(
bool x) {
309 proactive_resource_freshening_ = x;
312 void set_disable_rewrite_on_no_transform(
bool x) {
313 disable_rewrite_on_no_transform_ = x;
315 ServerContext* server_context_;
317 const ContentType* type_;
331 friend class DummyResource;
341 bool is_background_fetch_;
342 bool enable_cache_purge_;
343 bool proactive_resource_freshening_;
344 bool disable_rewrite_on_no_transform_;
345 bool is_authorized_domain_;
346 ResponseHeaders::VaryOption respect_vary_;
348 mutable bool extracted_;
bool loaded() const
Definition: resource.h:105
Definition: http_value.h:38
ServerContext * server_context() const
Common methods across all deriviations.
Definition: resource.h:77
Definition: callback.h:167
friend class ReadAsyncHttpCacheCallback
uses LoadAndCallback
Definition: resource.h:288
bool is_authorized_domain()
Definition: resource.h:86
Definition: resource.h:217
virtual bool IsValidAndCacheable() const
Definition: ref_counted_ptr.h:41
void LoadAsync(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)
virtual bool UseHttpCache() const =0
bool IsSafeToRewrite(bool rewrite_uncacheable, GoogleString *reason) const
Definition: resource.h:233
virtual InputInfo * input_info()
Definition: resource.h:241
virtual bool has_url() const
Definition: resource.h:200
bool IsSafeToRewrite(bool rewrite_uncacheable) const
Definition: resource.h:97
Definition: resource.h:57
int64 CacheExpirationTimeMs() const
NotCacheablePolicy
Definition: resource.h:68
virtual GoogleString url() const =0
Gets the absolute URL of the resource.
Callback2< const GoogleUrl &, bool * > ResourceUrlClaimant
Definition: resource.h:357
void AddInputInfoToPartition(HashHint suggest_include_content_hash, int index, CachedResult *partition)
bool Link(HTTPValue *source, MessageHandler *handler)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
HTTPValue value_
contains contents and meta-data
Definition: resource.h:319
void LinkFallbackValue(HTTPValue *value)
Links the stale fallback value that can be used in case a fetch fails.
virtual GoogleString UrlForDebug() const
Override if resource does not have a URL.
Definition: resource.h:202
bool ExtractContents(StringPiece *str) const
Definition: rewrite_driver.h:100
Definition: server_context.h:99
StringPiece ExtractUncompressedContents() const
Definition: content_type.h:31
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)=0
Definition: message_handler.h:39
FetchResponseStatus
Definition: http_cache_failure.h:33
virtual void RefreshIfImminentlyExpiring()
StringPiece charset() const
Note: this is empty if the header is not specified.
Definition: resource.h:193
GoogleString ContentsHash() const
virtual void Done(bool lock_failure, bool resource_ok)
Definition: resource.h:245
size_t UncompressedContentsSize() const
Definition: resource.h:171
virtual void FillInPartitionInputInfo(HashHint suggest_include_content_hash, InputInfo *input)
virtual void Freshen(FreshenCallback *callback, MessageHandler *handler)
virtual GoogleString cache_key() const
Definition: resource.h:206
void DetermineContentType()
HTTPValue fallback_value_
Definition: resource.h:325