Skip to content

Commit 9e59303

Browse files
committed
Add Shopify-Theme as a cacheable header
1 parent cb744f5 commit 9e59303

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/response_bank/middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ResponseBank
44
class Middleware
55
# Limit the cached headers
66
# TODO: Make this lowercase/case-insentitive as per rfc2616 §4.2
7-
CACHEABLE_HEADERS = ["Location", "Content-Type", "ETag", "Content-Encoding", "Last-Modified", "Cache-Control", "Expires", "Link", "Surrogate-Keys", "Cache-Tags", "Speculation-Rules"].freeze
7+
CACHEABLE_HEADERS = ["Location", "Content-Type", "ETag", "Content-Encoding", "Last-Modified", "Cache-Control", "Expires", "Link", "Surrogate-Keys", "Cache-Tags", "Speculation-Rules", "Shopify-Theme"].freeze
88

99
REQUESTED_WITH = "HTTP_X_REQUESTED_WITH"
1010
ACCEPT = "HTTP_ACCEPT"

lib/response_bank/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22
module ResponseBank
3-
VERSION = "1.3.6"
3+
VERSION = "1.3.7"
44
end

test/middleware_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ def spec_rules(env)
6161
[200, { 'Speculation-Rules' => '"https://shopify.com/specrules.json"' }, []]
6262
end
6363

64+
def cached_shopify_theme(env)
65+
env['cacheable.cache'] = true
66+
env['cacheable.miss'] = false
67+
env['cacheable.key'] = 'etag_value'
68+
env['cacheable.unversioned-key'] = 'cached_shopify_theme_cache_key'
69+
env['cacheable.store'] = 'server'
70+
71+
[200, { 'Shopify-Theme' => 'dawn-v1.2.3' }, []]
72+
end
73+
74+
def shopify_theme(env)
75+
env['cacheable.cache'] = true
76+
env['cacheable.miss'] = true
77+
env['cacheable.key'] = 'etag_value'
78+
env['cacheable.unversioned-key'] = 'shopify_theme_cache_key'
79+
80+
[200, { 'Shopify-Theme' => 'dawn-v1.2.3' }, []]
81+
end
82+
6483
def cacheable_app(env)
6584
env['cacheable.cache'] = true
6685
env['cacheable.miss'] = true
@@ -187,6 +206,26 @@ def test_cache_miss_and_specrules
187206
assert_equal('"https://shopify.com/specrules.json"', headers['Speculation-Rules'])
188207
end
189208

209+
def test_cache_hit_and_shopify_theme
210+
ResponseBank.cache_store.expects(:write).never
211+
212+
ware = ResponseBank::Middleware.new(method(:cached_shopify_theme))
213+
result = ware.call(@env)
214+
headers = result[1]
215+
216+
assert_equal('dawn-v1.2.3', headers['Shopify-Theme'])
217+
end
218+
219+
def test_cache_miss_and_shopify_theme
220+
ResponseBank.cache_store.expects(:write).once
221+
222+
ware = ResponseBank::Middleware.new(method(:shopify_theme))
223+
result = ware.call(@env)
224+
headers = result[1]
225+
226+
assert_equal('dawn-v1.2.3', headers['Shopify-Theme'])
227+
end
228+
190229
def test_cache_miss_and_store_limited_headers
191230
ResponseBank::Middleware.any_instance.stubs(timestamp: 424242)
192231
ResponseBank.cache_store.expects(:write).with(

0 commit comments

Comments
 (0)