mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-05 00:02:38 -04:00
added test for following redirects, added plugin scaffold, test fails, of course
This commit is contained in:
parent
a47ba100f5
commit
460c1346d2
19
lib/httpx/plugins/follow_redirects.rb
Normal file
19
lib/httpx/plugins/follow_redirects.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module HTTPX
|
||||
module Plugins
|
||||
module FollowRedirects
|
||||
module InstanceMethods
|
||||
end
|
||||
|
||||
module OptionsMethods
|
||||
def self.included(klass)
|
||||
super
|
||||
klass.def_option(:max_redirects)
|
||||
end
|
||||
end
|
||||
end
|
||||
register_plugin :follow_redirects, FollowRedirects
|
||||
end
|
||||
end
|
||||
|
35
test/support/requests/plugins/follow_redirects.rb
Normal file
35
test/support/requests/plugins/follow_redirects.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cgi"
|
||||
|
||||
module Requests
|
||||
module Plugins
|
||||
module FollowRedirects
|
||||
def test_plugin_follow_redirects
|
||||
no_redirect_response = HTTPX.get(redirect_uri)
|
||||
verify_status(no_redirect_response.status, 302)
|
||||
verify_header(no_redirect_response.headers, "location", redirect_location)
|
||||
|
||||
client = HTTPX.plugin(:follow_redirects)
|
||||
redirect_response = client.get(redirect_uri)
|
||||
verify_status(redirect_response.status, 200)
|
||||
require "pry-byebug" ; binding.pry
|
||||
end
|
||||
|
||||
def test_plugin_follow_redirects_max_redirects
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_uri
|
||||
build_uri("/redirect-to?url=" + CGI.escape(redirect_location))
|
||||
end
|
||||
|
||||
def redirect_location
|
||||
build_uri("/")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user