26 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_H_
27 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_H_
31 #include "base/logging.h"
33 #include "net/instaweb/http/public/meta_data.h"
35 #include "net/instaweb/http/public/response_headers.h"
37 #include "net/instaweb/util/public/ref_counted_ptr.h"
40 #include "pagespeed/kernel/base/callback.h"
42 namespace net_instaweb {
53 typedef RefCountedPtr<Resource> ResourcePtr;
54 typedef std::vector<ResourcePtr> ResourceVector;
68 kLoadEvenIfNotCacheable,
69 kReportFailureIfNotCacheable,
76 kFetchStatusUncacheable,
95 void set_is_authorized_domain(
bool is_authorized) {
96 is_authorized_domain_ = is_authorized;
104 bool IsSafeToRewrite(
bool rewrite_uncacheable, GoogleString* reason)
const;
107 GoogleString reason_ignored;
113 bool loaded()
const {
return response_headers_.status_code() != 0; }
114 bool HttpStatusOk()
const {
115 return (response_headers_.status_code() == HttpStatus::kOK);
127 const RequestContextPtr& request_context,
128 AsyncCallback* callback);
147 int index, CachedResult* partition);
162 void FillInPartitionInputInfoFromResponseHeaders(
163 const ResponseHeaders& headers,
171 StringPiece contents()
const {
174 CHECK(got_contents) <<
"Resource contents read before loading: " <<
url();
177 ResponseHeaders* response_headers() {
return &response_headers_; }
178 const ResponseHeaders* response_headers()
const {
return &response_headers_; }
179 const ContentType* type()
const {
return type_; }
180 virtual void SetType(
const ContentType* type);
183 StringPiece
charset()
const {
return charset_; }
184 void set_charset(StringPiece c) { c.CopyToString(&charset_); }
187 virtual GoogleString
url()
const = 0;
204 explicit AsyncCallback(
const ResourcePtr& resource) : resource_(resource) {}
207 virtual void Done(
bool lock_failure,
bool resource_ok) = 0;
209 const ResourcePtr& resource() {
return resource_; }
212 ResourcePtr resource_;
230 virtual void Done(
bool lock_failure,
bool resource_ok) {
248 virtual void Freshen(FreshenCallback* callback, MessageHandler* handler);
253 void set_is_background_fetch(
bool x) { is_background_fetch_ = x; }
254 bool is_background_fetch()
const {
return is_background_fetch_; }
257 return fetch_response_status_;
261 fetch_response_status_ = x;
271 REFCOUNT_FRIEND_DECLARATION(Resource);
272 friend class ServerContext;
275 friend class UrlReadAsyncFetchCallback;
287 const RequestContextPtr& request_context,
290 void set_enable_cache_purge(
bool x) { enable_cache_purge_ = x; }
291 ResponseHeaders::VaryOption respect_vary()
const {
return respect_vary_; }
292 void set_respect_vary(ResponseHeaders::VaryOption x) { respect_vary_ = x; }
293 void set_proactive_resource_freshening(
bool x) {
294 proactive_resource_freshening_ = x;
297 void set_disable_rewrite_on_no_transform(
bool x) {
298 disable_rewrite_on_no_transform_ = x;
300 ServerContext* server_context_;
302 const ContentType* type_;
303 GoogleString charset_;
305 ResponseHeaders response_headers_;
316 friend class DummyResource;
326 bool is_background_fetch_;
327 bool enable_cache_purge_;
328 bool proactive_resource_freshening_;
329 bool disable_rewrite_on_no_transform_;
330 bool is_authorized_domain_;
331 ResponseHeaders::VaryOption respect_vary_;
bool loaded() const
Definition: resource.h:113
Definition: http_value.h:36
ServerContext * server_context() const
Common methods across all deriviations.
Definition: resource.h:85
friend class ReadAsyncHttpCacheCallback
uses LoadAndCallback
Definition: resource.h:273
bool is_authorized_domain()
Definition: resource.h:94
Definition: resource.h:202
virtual bool IsValidAndCacheable() const
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:218
virtual InputInfo * input_info()
Definition: resource.h:226
bool IsSafeToRewrite(bool rewrite_uncacheable) const
Definition: resource.h:105
Definition: resource.h:56
int64 CacheExpirationTimeMs() const
NotCacheablePolicy
Definition: resource.h:67
virtual GoogleString url() const =0
Gets the absolute URL of the resource.
Callback2< const GoogleUrl &, bool * > ResourceUrlClaimant
Definition: resource.h:340
void AddInputInfoToPartition(HashHint suggest_include_content_hash, int index, CachedResult *partition)
bool Link(HTTPValue *source, MessageHandler *handler)
HTTPValue value_
contains contents and meta-data
Definition: resource.h:304
void LinkFallbackValue(HTTPValue *value)
Links the stale fallback value that can be used in case a fetch fails.
bool ExtractContents(StringPiece *str) const
Definition: rewrite_driver.h:98
Definition: server_context.h:100
virtual void LoadAndCallback(NotCacheablePolicy not_cacheable_policy, const RequestContextPtr &request_context, AsyncCallback *callback)=0
FetchResponseStatus
This enumerates different states of the fetched response.
Definition: resource.h:73
virtual void RefreshIfImminentlyExpiring()
StringPiece charset() const
Note: this is empty if the header is not specified.
Definition: resource.h:183
GoogleString ContentsHash() const
virtual void Done(bool lock_failure, bool resource_ok)
Definition: resource.h:230
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:191
void DetermineContentType()
HTTPValue fallback_value_
Definition: resource.h:310