Compare commits

...

3 Commits

Author SHA1 Message Date
HoneyryderChuck
5bc2949a49 Merge branch 'issue-239' into 'master'
added #bearer_auth helper in authentication pluginn

Closes #239

See merge request os85/httpx!265
2023-07-03 21:31:39 +00:00
HoneyryderChuck
1a2db03c26 resolver_options: allow nameserver to be an hash descriminating dns server by socket family 2023-07-03 22:30:53 +01:00
HoneyryderChuck
17a26be1a9 added #bearer_auth helper in authentication pluginn 2023-07-02 22:23:07 +01:00
4 changed files with 22 additions and 2 deletions

View File

@ -13,6 +13,10 @@ module HTTPX
def authentication(token)
with(headers: { "authorization" => token })
end
def bearer_auth(token)
authentication("Bearer #{token}")
end
end
end
register_plugin :authentication, Authentication

View File

@ -29,12 +29,15 @@ module HTTPX
attr_reader :state
def initialize(_, options)
def initialize(family, options)
super
@ns_index = 0
@resolver_options = DEFAULTS.merge(@options.resolver_options)
@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]
@search = Array(@resolver_options[:search]).map { |srch| srch.scan(/[^.]+/) }
@_timeouts = Array(@resolver_options[:timeouts])

View File

@ -3,6 +3,8 @@ module HTTPX
module Authentication
module InstanceMethods
def authentication: (string token) -> instance
def bearer_auth: (string token) -> instance
end
end

View File

@ -3,6 +3,17 @@
module Requests
module Plugins
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
def test_plugin_basic_authentication