2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmarantz@google.com (Joshua Marantz)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_CACHE_EXTENDER_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_CACHE_EXTENDER_H_
22
#include "net/instaweb/rewriter/public/resource.h" // for ResourcePtr
23
#include "net/instaweb/rewriter/public/server_context.h"
24
#include "net/instaweb/rewriter/public/resource_slot.h"
25
#include "net/instaweb/rewriter/public/rewrite_filter.h"
26
#include "net/instaweb/rewriter/public/rewrite_options.h"
27
#include "net/instaweb/rewriter/public/rewrite_result.h"
28
#include "net/instaweb/util/public/basictypes.h"
29
#include "net/instaweb/util/public/string_util.h"
31
namespace net_instaweb {
35
class ResponseHeaders;
41
// Rewrites resources without changing their content -- just their
42
// URLs and headers. The original intent of this filter was limited
43
// to cache extension. However, its scope has been expanded to include
44
// domain sharding and moving static resources to cookieless domains or
47
// TODO(jmarantz): rename this class to something more generic, like
48
// RenameUrlFilter or ProxyUrlFilter.
49
class CacheExtender : public RewriteFilter {
51
static const char kCacheExtensions[];
52
static const char kNotCacheable[];
54
explicit CacheExtender(RewriteDriver* driver);
55
virtual ~CacheExtender();
57
static void InitStats(Statistics* statistics);
59
virtual void StartDocumentImpl() {}
60
virtual void StartElementImpl(HtmlElement* element);
61
virtual void EndElementImpl(HtmlElement* element) {}
63
virtual const char* Name() const { return "CacheExtender"; }
64
virtual const char* id() const { return RewriteOptions::kCacheExtenderId; }
66
// Creates a nested rewrite for given parent and slot, and returns it.
67
// The result is not registered with the parent.
68
RewriteContext* MakeNestedContext(RewriteContext* parent,
69
const ResourceSlotPtr& slot);
72
virtual bool ComputeOnTheFly() const;
73
virtual RewriteContext* MakeRewriteContext();
79
RewriteResult RewriteLoadedResource(const ResourcePtr& input_resource,
80
const OutputResourcePtr& output_resource,
81
CachedResult* result);
83
bool ShouldRewriteResource(
84
const ResponseHeaders* headers, int64 now_ms,
85
const ResourcePtr& input_resource, const StringPiece& url,
86
CachedResult* result) const;
88
Variable* extension_count_;
89
Variable* not_cacheable_count_;
91
DISALLOW_COPY_AND_ASSIGN(CacheExtender);
94
} // namespace net_instaweb
96
#endif // NET_INSTAWEB_REWRITER_PUBLIC_CACHE_EXTENDER_H_