Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/response_bank/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ResponseBank
class Middleware
# Limit the cached headers
# TODO: Make this lowercase/case-insentitive as per rfc2616 §4.2
CACHEABLE_HEADERS = ["Location", "Content-Type", "ETag", "Content-Encoding", "Last-Modified", "Cache-Control", "Expires", "Link", "Surrogate-Keys", "Cache-Tags", "Speculation-Rules"].freeze
CACHEABLE_HEADERS = ["Location", "Content-Type", "ETag", "Content-Encoding", "Last-Modified", "Cache-Control", "Expires", "Link", "Surrogate-Keys", "Cache-Tags", "Speculation-Rules", "Shopify-Theme"].freeze

REQUESTED_WITH = "HTTP_X_REQUESTED_WITH"
ACCEPT = "HTTP_ACCEPT"
Expand Down
2 changes: 1 addition & 1 deletion lib/response_bank/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module ResponseBank
VERSION = "1.3.6"
VERSION = "1.3.7"
end
39 changes: 39 additions & 0 deletions test/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ def spec_rules(env)
[200, { 'Speculation-Rules' => '"https://shopify.com/specrules.json"' }, []]
end

def cached_shopify_theme(env)
env['cacheable.cache'] = true
env['cacheable.miss'] = false
env['cacheable.key'] = 'etag_value'
env['cacheable.unversioned-key'] = 'cached_shopify_theme_cache_key'
env['cacheable.store'] = 'server'

[200, { 'Shopify-Theme' => 'dawn-v1.2.3' }, []]
end

def shopify_theme(env)
env['cacheable.cache'] = true
env['cacheable.miss'] = true
env['cacheable.key'] = 'etag_value'
env['cacheable.unversioned-key'] = 'shopify_theme_cache_key'

[200, { 'Shopify-Theme' => 'dawn-v1.2.3' }, []]
end

def cacheable_app(env)
env['cacheable.cache'] = true
env['cacheable.miss'] = true
Expand Down Expand Up @@ -187,6 +206,26 @@ def test_cache_miss_and_specrules
assert_equal('"https://shopify.com/specrules.json"', headers['Speculation-Rules'])
end

def test_cache_hit_and_shopify_theme
ResponseBank.cache_store.expects(:write).never

ware = ResponseBank::Middleware.new(method(:cached_shopify_theme))
result = ware.call(@env)
headers = result[1]

assert_equal('dawn-v1.2.3', headers['Shopify-Theme'])
end

def test_cache_miss_and_shopify_theme
ResponseBank.cache_store.expects(:write).once

ware = ResponseBank::Middleware.new(method(:shopify_theme))
result = ware.call(@env)
headers = result[1]

assert_equal('dawn-v1.2.3', headers['Shopify-Theme'])
end

def test_cache_miss_and_store_limited_headers
ResponseBank::Middleware.any_instance.stubs(timestamp: 424242)
ResponseBank.cache_store.expects(:write).with(
Expand Down