mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-06 00:02:08 -04:00
Fix initial headers always being an instance of the default header class
This commit is contained in:
parent
a839c2d6f1
commit
91fba0a971
@ -47,13 +47,13 @@ module HTTPX
|
||||
write_timeout: WRITE_TIMEOUT,
|
||||
request_timeout: REQUEST_TIMEOUT,
|
||||
},
|
||||
:headers_class => Class.new(Headers),
|
||||
:headers => {},
|
||||
:window_size => WINDOW_SIZE,
|
||||
:buffer_size => BUFFER_SIZE,
|
||||
:body_threshold_size => MAX_BODY_THRESHOLD_SIZE,
|
||||
:request_class => Class.new(Request),
|
||||
:response_class => Class.new(Response),
|
||||
:headers_class => Class.new(Headers),
|
||||
:request_body_class => Class.new(Request::Body),
|
||||
:response_body_class => Class.new(Response::Body),
|
||||
:connection_class => Class.new(Connection),
|
||||
@ -154,7 +154,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def option_headers(value)
|
||||
Headers.new(value)
|
||||
headers_class.new(value)
|
||||
end
|
||||
|
||||
def option_timeout(value)
|
||||
|
@ -61,7 +61,7 @@ module HTTPX
|
||||
@uri = origin.merge("#{base_path}#{@uri}")
|
||||
end
|
||||
|
||||
@headers = @options.headers_class.new(@options.headers)
|
||||
@headers = @options.headers.dup
|
||||
@headers["user-agent"] ||= USER_AGENT
|
||||
@headers["accept"] ||= "*/*"
|
||||
|
||||
|
@ -45,6 +45,17 @@ class OptionsTest < Minitest::Test
|
||||
assert opt2.headers.to_a == [%w[accept */*]], "headers are unexpected"
|
||||
end
|
||||
|
||||
def test_options_headers_with_instance
|
||||
proc_headers_class = Class.new(HTTPX::Headers) do
|
||||
def initialize(headers = nil)
|
||||
super(headers.transform_values(&:call))
|
||||
end
|
||||
end
|
||||
|
||||
opts = Options.new(headers_class: proc_headers_class, headers: { "x-number" => -> { 1 + 1 } })
|
||||
assert_equal "2", opts.headers["x-number"]
|
||||
end
|
||||
|
||||
def test_options_merge_hash
|
||||
opts = Options.new(body: "fat")
|
||||
merged_opts = opts.merge(body: "thin")
|
||||
|
Loading…
x
Reference in New Issue
Block a user