Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IE8 workaround for ajax calls #70

Merged
merged 2 commits into from
Mar 31, 2023
Merged
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
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PATH
specs:
response_bank (1.2.0)
msgpack
useragent

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -100,7 +99,7 @@ GEM
minitest (5.18.0)
mocha (2.0.2)
ruby2_keywords (>= 0.0.5)
msgpack (1.6.1)
msgpack (1.7.0)
net-imap (0.3.4)
date
net-protocol
Expand Down Expand Up @@ -176,7 +175,6 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
useragent (0.16.10)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down
13 changes: 0 additions & 13 deletions lib/response_bank/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require 'useragent'

module ResponseBank
class Middleware
Expand All @@ -25,9 +24,6 @@ def call(env)
if [200, 404, 301, 304].include?(status)
headers['ETag'] = env['cacheable.key']

if ie_ajax_request?(env)
headers["Expires"] = "-1"
end
end

if [200, 404, 301].include?(status) && env['cacheable.miss']
Expand Down Expand Up @@ -79,14 +75,5 @@ def timestamp
Time.now.to_i
end

def ie_ajax_request?(env)
return false unless !env[USER_AGENT].nil? && !env[USER_AGENT].empty?

if env[REQUESTED_WITH] == "XmlHttpRequest" || env[ACCEPT] == "application/json"
UserAgent.parse(env["HTTP_USER_AGENT"]).is_a?(UserAgent::Browsers::InternetExplorer)
else
false
end
end
end
end
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.2.0"
VERSION = "1.2.1"
end
1 change: 0 additions & 1 deletion response_bank.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |s|

s.metadata["allowed_push_host"] = "https://rubygems.org"

s.add_runtime_dependency("useragent")
s.add_runtime_dependency("msgpack")

s.add_development_dependency("minitest", ">= 5.18.0")
Expand Down
42 changes: 0 additions & 42 deletions test/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,46 +300,4 @@ def test_cache_hit_client
assert_equal('client', env['cacheable.store'])
assert_equal('"etag_value"', headers['ETag'])
end

def test_ie_ajax
ware = ResponseBank::Middleware.new(method(:already_cached_app))
env = Rack::MockRequest.env_for("http://example.com/index.html")

assert(!ware.send(:ie_ajax_request?, env))

env = Rack::MockRequest.env_for("http://example.com/index.html")
env["HTTP_USER_AGENT"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"

assert(!ware.send(:ie_ajax_request?, env))

env = Rack::MockRequest.env_for("http://example.com/index.html")
env["HTTP_USER_AGENT"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
env["HTTP_X_REQUESTED_WITH"] = "XmlHttpRequest"

assert(ware.send(:ie_ajax_request?, env))

env = Rack::MockRequest.env_for("http://example.com/index.html")
env["HTTP_USER_AGENT"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
env["HTTP_ACCEPT"] = "application/json"

assert(ware.send(:ie_ajax_request?, env))
end

def test_cache_hit_server_with_ie_ajax
ResponseBank.cache_store.expects(:write).times(0)

env = Rack::MockRequest.env_for("http://example.com/index.html")
env["HTTP_USER_AGENT"] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
env["HTTP_X_REQUESTED_WITH"] = "XmlHttpRequest"

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

assert(env['cacheable.cache'])
assert(!env['cacheable.miss'])
assert_equal('server', env['cacheable.store'])
assert_equal('"etag_value"', headers['ETag'])
assert_equal("-1", headers['Expires'])
end
end