mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
added plugin tests, and the plugin body
This commit is contained in:
parent
5bafed433a
commit
a60fde07d6
14
lib/httpx/plugins/response_cache.rb
Normal file
14
lib/httpx/plugins/response_cache.rb
Normal file
@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module HTTPX
|
||||
module Plugins
|
||||
#
|
||||
# This plugin adds support for retrying requests when certain errors happen.
|
||||
#
|
||||
# https://gitlab.com/honeyryderchuck/httpx/wikis/Response-Cache
|
||||
#
|
||||
module ResponseCache
|
||||
end
|
||||
register_plugin :response_cache, ResponseCache
|
||||
end
|
||||
end
|
@ -30,6 +30,7 @@ class HTTPTest < Minitest::Test
|
||||
include Plugins::AWSAuthentication
|
||||
include Plugins::Upgrade
|
||||
include Plugins::GRPC if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0"
|
||||
include Plugins::ResponseCache
|
||||
|
||||
def test_verbose_log
|
||||
log = StringIO.new
|
||||
|
@ -31,6 +31,7 @@ class HTTPSTest < Minitest::Test
|
||||
include Plugins::AWSAuthentication
|
||||
include Plugins::Upgrade
|
||||
include Plugins::GRPC if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0"
|
||||
include Plugins::ResponseCache
|
||||
|
||||
def test_connection_coalescing
|
||||
coalesced_origin = "https://#{ENV["HTTPBIN_COALESCING_HOST"]}"
|
||||
|
47
test/support/requests/plugins/response_cache.rb
Normal file
47
test/support/requests/plugins/response_cache.rb
Normal file
@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "securerandom"
|
||||
|
||||
module Requests
|
||||
module Plugins
|
||||
module ResponseCache
|
||||
def test_plugin_response_cache_etag
|
||||
cache_client = HTTPX.plugin(:response_cache)
|
||||
etag = SecureRandom.hex
|
||||
|
||||
etag_uri = build_uri("/cache")
|
||||
|
||||
uncached = cache_client.get(etag_uri)
|
||||
verify_status(uncached, 200)
|
||||
cached = cache_client.get(etag_uri)
|
||||
verify_status(cached, 304)
|
||||
|
||||
assert uncached.body == cached.body
|
||||
|
||||
cached.clear_response_cache
|
||||
|
||||
uncached = cache_client.get(etag_uri)
|
||||
verify_status(uncached, 200)
|
||||
end
|
||||
|
||||
def test_plugin_response_cache_cache_control
|
||||
cache_client = HTTPX.plugin(:response_cache)
|
||||
cache_control = 2
|
||||
|
||||
cache_control_uri = build_uri("/cache/#{cache_control}")
|
||||
|
||||
uncached = cache_client.get(cache_control_uri)
|
||||
verify_status(uncached, 200)
|
||||
cached = cache_client.get(cache_control_uri)
|
||||
verify_status(cached, 304)
|
||||
|
||||
assert uncached == cached
|
||||
sleep(2)
|
||||
expired = cache_client.get(cache_control_uri)
|
||||
verify_status(expired, 200)
|
||||
|
||||
assert expired != uncached
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user