mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-09-30 00:01:02 -04:00
added support for plugin pimping the request body, remove the content-encoding logic there
This commit is contained in:
parent
f80d6dd175
commit
72b90c3f17
@ -154,6 +154,8 @@ module HTTPX
|
||||
default_options.response_class.extend(pl::ResponseClassMethods) if defined?(pl::ResponseClassMethods)
|
||||
default_options.headers_class.__send__(:include, pl::HeadersMethods) if defined?(pl::HeadersMethods)
|
||||
default_options.headers_class.extend(pl::HeadersClassMethods) if defined?(pl::HeadersClassMethods)
|
||||
default_options.request_body_class.__send__(:include, pl::RequestBodyMethods) if defined?(pl::RequestBodyMethods)
|
||||
default_options.request_body_class.extend(pl::RequestBodyClassMethods) if defined?(pl::RequestBodyClassMethods)
|
||||
default_options.response_body_class.__send__(:include, pl::ResponseBodyMethods) if defined?(pl::ResponseBodyMethods)
|
||||
default_options.response_body_class.extend(pl::ResponseBodyClassMethods) if defined?(pl::ResponseBodyClassMethods)
|
||||
pl.configure(self, *args, &block) if pl.respond_to?(:configure)
|
||||
|
@ -53,6 +53,7 @@ module HTTPX
|
||||
: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),
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ module HTTPX
|
||||
%w[
|
||||
params form json body
|
||||
follow ssl http2_settings max_retries
|
||||
request_class response_class headers_class response_body_class
|
||||
request_class response_class headers_class request_body_class response_body_class
|
||||
io fallback_protocol debug debug_level
|
||||
].each do |method_name|
|
||||
def_option(method_name)
|
||||
@ -122,6 +123,7 @@ module HTTPX
|
||||
dupped.request_class = request_class.dup
|
||||
dupped.response_class = response_class.dup
|
||||
dupped.headers_class = headers_class.dup
|
||||
dupped.request_body_class = request_body_class.dup
|
||||
dupped.response_body_class = response_body_class.dup
|
||||
yield(dupped) if block_given?
|
||||
dupped
|
||||
|
@ -50,7 +50,7 @@ module HTTPX
|
||||
@headers["user-agent"] ||= USER_AGENT
|
||||
@headers["accept"] ||= "*/*"
|
||||
|
||||
@body = Body.new(@headers, @options)
|
||||
@body = @options.request_body_class.new(@headers, @options)
|
||||
@state = :idle
|
||||
end
|
||||
|
||||
@ -113,11 +113,8 @@ module HTTPX
|
||||
Transcoder.registry("json").encode(options.json)
|
||||
end
|
||||
return if @body.nil?
|
||||
@headers.get("content-encoding").each do |encoding|
|
||||
@body = Transcoder.registry(encoding).encode(@body)
|
||||
end
|
||||
@headers["content-type"] ||= @body.content_type
|
||||
@headers["content-length"] ||= @body.bytesize unless chunked?
|
||||
@headers["content-length"] = @body.bytesize unless chunked?
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
|
@ -24,6 +24,11 @@ class ClientTest < Minitest::Test
|
||||
assert request.headers.respond_to?(:foo), "headers methods haven't been added"
|
||||
assert request.headers.foo == "headers-foo", "headers method is unexpected"
|
||||
assert client.respond_to?(:response), "response constructor was added"
|
||||
|
||||
req_body = request.body
|
||||
assert req_body.respond_to?(:foo), "request body methods haven't been added"
|
||||
assert req_body.foo == "request-body-foo", "request body method is unexpected"
|
||||
|
||||
response = client.response(nil, 200, "2.0", {})
|
||||
assert response.respond_to?(:foo), "response methods haven't been added"
|
||||
assert response.foo == "response-foo", "response method is unexpected"
|
||||
@ -76,6 +81,16 @@ class ClientTest < Minitest::Test
|
||||
self.class.foo
|
||||
end
|
||||
end
|
||||
self::RequestBodyClassMethods = Module.new do
|
||||
def foo
|
||||
"request-body-foo"
|
||||
end
|
||||
end
|
||||
self::RequestBodyMethods = Module.new do
|
||||
def foo
|
||||
self.class.foo
|
||||
end
|
||||
end
|
||||
self::ResponseClassMethods = Module.new do
|
||||
def foo
|
||||
"response-foo"
|
||||
|
@ -74,6 +74,7 @@ class OptionsSpec < Minitest::Test
|
||||
:request_class => bar.request_class,
|
||||
:response_class => bar.response_class,
|
||||
:headers_class => bar.headers_class,
|
||||
:request_body_class => bar.request_body_class,
|
||||
:response_body_class => bar.response_body_class,
|
||||
}, "options haven't merged correctly"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user