Skip to content
Browse files

added support for boolean values when making POST/PUT requests with m…

…ultipart/form Content-Type
  • Loading branch information...
1 parent c86ece5 commit 6bc466b2f3b7c07360eee4e0dc66f7e23c7c8c71 @pinge pinge committed
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/httpclient/http.rb
  2. +12 −0 test/test_httpclient.rb
View
2 lib/httpclient/http.rb
@@ -633,7 +633,7 @@ def parts
def build_query_multipart_str(query, boundary)
parts = Parts.new
query.each do |attr, value|
- value ||= ''
+ value = '' if value.nil?
headers = ["--#{boundary}"]
if Message.file?(value)
remember_pos(value)
View
12 test/test_httpclient.rb
@@ -685,6 +685,18 @@ def test_post_with_content_type
assert_equal("post,--hello\r\nContent-Disposition: form-data; name=\"1\"\r\n\r\n2\r\n--hello\r\nContent-Disposition: form-data; name=\"3\"\r\n\r\n4\r\n--hello--\r\n\r\n", res.content)
end
+ def test_post_with_custom_multipart_and_boolean_params
+ param = [['boolean_true', true]]
+ ext = { 'content-type' => 'multipart/form-data' }
+ assert_equal("post", @client.post(serverurl + 'servlet').content[0, 4], ext)
+ res = @client.post(serverurl + 'servlet', param, ext)
+ assert_match(/Content-Disposition: form-data; name="boolean_true"\r\n\r\ntrue\r\n/, res.content)
+ #
+ param = [['boolean_false', false]]
+ res = @client.post(serverurl + 'servlet', param, ext)
+ assert_match(/Content-Disposition: form-data; name="boolean_false"\r\n\r\nfalse\r\n/, res.content)
+ end
+
def test_post_with_file
STDOUT.sync = true
File.open(__FILE__) do |file|

0 comments on commit 6bc466b

Please sign in to comment.
Something went wrong with that request. Please try again.