mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-15 00:00:39 -04:00
added support for :expect_threshold_size, to disable expect: 100-continue based on body bytesize sent
This commit is contained in:
parent
8df9b06cd0
commit
93a4b933af
@ -18,14 +18,27 @@ module HTTPX
|
||||
|
||||
seconds
|
||||
end
|
||||
|
||||
def_option(:expect_threshold_size) do |bytes|
|
||||
bytes = Integer(bytes)
|
||||
raise Error, ":expect_threshold_size must be positive" unless bytes.positive?
|
||||
|
||||
bytes
|
||||
end
|
||||
end.new(options).merge(expect_timeout: EXPECT_TIMEOUT)
|
||||
end
|
||||
|
||||
module RequestBodyMethods
|
||||
def initialize(*)
|
||||
def initialize(*, options)
|
||||
super
|
||||
return if @body.nil?
|
||||
|
||||
if (threshold = options.expect_threshold_size)
|
||||
unless unbounded_body?
|
||||
return if @body.bytesize < threshold
|
||||
end
|
||||
end
|
||||
|
||||
@headers["expect"] = "100-continue"
|
||||
end
|
||||
end
|
||||
|
@ -13,6 +13,20 @@ module Requests
|
||||
verify_uploaded(body, "form", "foo" => "bar")
|
||||
end
|
||||
|
||||
def test_plugin_expect_100_form_params_under_threshold
|
||||
uri = build_uri("/post")
|
||||
session = HTTPX.plugin(:expect, expect_threshold_size: 4)
|
||||
response = session.post(uri, body: "a" * 3)
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_no_header(body["headers"], "Expect")
|
||||
|
||||
response = session.post(uri, body: "a" * 5)
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Expect", "100-continue")
|
||||
end
|
||||
|
||||
# def test_plugin_expect_100_send_body_after_delay
|
||||
# uri = build_uri("/delay/3")
|
||||
# response = HTTPX.plugin(:expect).post(uri, form: { "foo" => "bar" })
|
||||
|
Loading…
x
Reference in New Issue
Block a user