mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-09 00:02:47 -05: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
|
seconds
|
||||||
end
|
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.new(options).merge(expect_timeout: EXPECT_TIMEOUT)
|
||||||
end
|
end
|
||||||
|
|
||||||
module RequestBodyMethods
|
module RequestBodyMethods
|
||||||
def initialize(*)
|
def initialize(*, options)
|
||||||
super
|
super
|
||||||
return if @body.nil?
|
return if @body.nil?
|
||||||
|
|
||||||
|
if (threshold = options.expect_threshold_size)
|
||||||
|
unless unbounded_body?
|
||||||
|
return if @body.bytesize < threshold
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@headers["expect"] = "100-continue"
|
@headers["expect"] = "100-continue"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,20 @@ module Requests
|
|||||||
verify_uploaded(body, "form", "foo" => "bar")
|
verify_uploaded(body, "form", "foo" => "bar")
|
||||||
end
|
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
|
# def test_plugin_expect_100_send_body_after_delay
|
||||||
# uri = build_uri("/delay/3")
|
# uri = build_uri("/delay/3")
|
||||||
# response = HTTPX.plugin(:expect).post(uri, form: { "foo" => "bar" })
|
# response = HTTPX.plugin(:expect).post(uri, form: { "foo" => "bar" })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user