mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-07-17 00:00:38 -04:00
Compare commits
3 Commits
3ec44fd56a
...
5bc2949a49
Author | SHA1 | Date | |
---|---|---|---|
|
5bc2949a49 | ||
|
1a2db03c26 | ||
|
17a26be1a9 |
@ -13,6 +13,10 @@ module HTTPX
|
|||||||
def authentication(token)
|
def authentication(token)
|
||||||
with(headers: { "authorization" => token })
|
with(headers: { "authorization" => token })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bearer_auth(token)
|
||||||
|
authentication("Bearer #{token}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
register_plugin :authentication, Authentication
|
register_plugin :authentication, Authentication
|
||||||
|
@ -29,12 +29,15 @@ module HTTPX
|
|||||||
|
|
||||||
attr_reader :state
|
attr_reader :state
|
||||||
|
|
||||||
def initialize(_, options)
|
def initialize(family, options)
|
||||||
super
|
super
|
||||||
@ns_index = 0
|
@ns_index = 0
|
||||||
@resolver_options = DEFAULTS.merge(@options.resolver_options)
|
@resolver_options = DEFAULTS.merge(@options.resolver_options)
|
||||||
@socket_type = @resolver_options.fetch(:socket_type, :udp)
|
@socket_type = @resolver_options.fetch(:socket_type, :udp)
|
||||||
@nameserver = Array(@resolver_options[:nameserver]) if @resolver_options[:nameserver]
|
@nameserver = if (nameserver = @resolver_options[:nameserver])
|
||||||
|
nameserver = nameserver[family] if nameserver.is_a?(Hash)
|
||||||
|
Array(nameserver)
|
||||||
|
end
|
||||||
@ndots = @resolver_options[:ndots]
|
@ndots = @resolver_options[:ndots]
|
||||||
@search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) }
|
@search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) }
|
||||||
@_timeouts = Array(@resolver_options[:timeouts])
|
@_timeouts = Array(@resolver_options[:timeouts])
|
||||||
|
@ -3,6 +3,8 @@ module HTTPX
|
|||||||
module Authentication
|
module Authentication
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def authentication: (string token) -> instance
|
def authentication: (string token) -> instance
|
||||||
|
|
||||||
|
def bearer_auth: (string token) -> instance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,17 @@
|
|||||||
module Requests
|
module Requests
|
||||||
module Plugins
|
module Plugins
|
||||||
module Authentication
|
module Authentication
|
||||||
|
# Bearer Auth
|
||||||
|
|
||||||
|
def test_plugin_bearer_auth
|
||||||
|
get_uri = build_uri("/get")
|
||||||
|
session = HTTPX.plugin(:authentication)
|
||||||
|
response = session.bearer_auth("TOKEN").get(get_uri)
|
||||||
|
verify_status(response, 200)
|
||||||
|
body = json_body(response)
|
||||||
|
verify_header(body["headers"], "Authorization", "Bearer TOKEN")
|
||||||
|
end
|
||||||
|
|
||||||
# Basic Auth
|
# Basic Auth
|
||||||
|
|
||||||
def test_plugin_basic_authentication
|
def test_plugin_basic_authentication
|
||||||
|
Loading…
x
Reference in New Issue
Block a user