-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTParty.post is unusable #774
Comments
Could you please provide a reproduction example |
@john-h-k Were you able to fix this issue ? I am also getting this on HTTParty.get while passing query params. |
➕ 1️⃣ on the breaking change. We started getting the same error after updating it to 0.21.0 |
I'm still waiting for any reproduction example. So, I could debug and fix it |
@TheSmartnik We're also getting this error after updating to 0.21.0. In our case, when we issue a request that responds with 422 Unprocessable Entity, the response Hope that helps. |
We would like to upgrade to 0.21 per the security advisory, but are concerned about this issue, despite being unable to reproduce it using the following script. @mikevoets, could you please use this script as a starting point to give @TheSmartnik something they can work with? # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
ruby "3.1.2"
source "https://rubygems.org"
gem "httparty", "0.21.0"
gem "minitest", "5.17.0"
gem "webmock", "3.18.1"
end
require 'webmock/minitest'
require 'minitest/autorun'
class BugTest < Minitest::Test
MOCK_URL = 'http://www.example.com/api'
def test_1
stub_request(:post, MOCK_URL).to_return(
body: "[]",
status: 422,
headers: { 'Content-Type' => 'application/json' }
)
HTTParty.post(MOCK_URL)
end
end |
@jaredbeck @TheSmartnik Sure thing! Here's the repro script. The only notable difference here is that the response is an array literal # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
ruby "2.7.6"
source "https://rubygems.org"
gem "httparty", "0.21.0"
gem "minitest", "5.17.0"
gem "webmock", "3.18.1"
end
require 'webmock/minitest'
require 'minitest/autorun'
class BugTest < Minitest::Test
MOCK_URL = 'http://www.example.com/api'
def test_1
stub_request(:post, MOCK_URL).to_return(
body: [],
status: 422,
headers: { 'Content-Type' => 'application/json' }
)
HTTParty.post(MOCK_URL)
end
end |
@mikevoets Thanks for the reproduction 🙇 I've stumbled upon the same error when trying to upgrade I've fixed it by using a I am wondering when After reading the implementation and tests of Net::HTTP I see no evidence that body can be something else but a WDYT? @mikevoets @john-h-k Do you have a reproduction which happened in a real-world (non-test/spec) scenario? 🤔 |
Nope, been purely on specs for me. I am trying that fix too. I am personally of the opinion it would make sense to change it to be non breaking, to make peoples lives' easier, but as it is outside of the proper usage I would also consider this issue resolved if that fix works for everyone + the maintainers decide they do not wish to change it |
Same for me - it only fails on tests. |
Summary: It's been awhile since I have looked at any sort of HTTP library. I've used HTTParty and Faraday in the past so I looked at both of the github pages, specifically the issues pages. I landed on faraday over HTTParty because of one particular issue that was filed. [Issue #744](jnunemaker/httparty#774) was a deal breaker for me. I just don't want to deal with using HTTParty.post and getting unexpected behavior.
This patch would fix it. I tested with the benchmarking tool @TheSmartnik linked and it doesn't seem to reintroduce the memory leak: diff --git a/lib/httparty/text_encoder.rb b/lib/httparty/text_encoder.rb
index 006893e..a8302d1 100644
--- a/lib/httparty/text_encoder.rb
+++ b/lib/httparty/text_encoder.rb
@@ -5,7 +5,7 @@ module HTTParty
attr_reader :text, :content_type, :assume_utf16_is_big_endian
def initialize(text, assume_utf16_is_big_endian: true, content_type: nil)
- @text = +text
+ @text = +String(text)
@content_type = content_type
@assume_utf16_is_big_endian = assume_utf16_is_big_endian
end I think @splattael (:wave:) is right though. The specs/fixtures should be changed to use Strings instead of Arrays. |
The fault, dear Brutus, is not in our gems, but in our specs .. sounds like we can close this one :) |
#754 was a breaking change for us and ever since we have gotten
undefined method
+@' for ["Not found"]:Array` errors continuously whenever trying to use HTTPartyThe text was updated successfully, but these errors were encountered: