Breaking change in net-http gem to exclude default content type
According to the discussion here, the net-http gem will no longer set a default content type. (From v0.7.0)
# Previous
set_content_type 'application/x-www-form-urlencoded'
# New
n/a
Impact
This might change the behavior of HTTP requests that directly or indirectly (E.g., httparty) rely on the net-http gem.
Example: Google Recaptcha API
# Works previously
post("https://www.google.com/recaptcha/api/siteverify", body: { secret: secret_key, response: token, remoteip: remote_ip })
=> {"success" => true, "challenge_ts" => "...", "hostname" => "...", "score" => 0.9, "action" => "login"}
# Fails after upgrading net-http gem
post("https://www.google.com/recaptcha/api/siteverify", body: { secret: secret_key, response: token, remoteip: remote_ip })
=> {"success" => false, "error-codes" => ["invalid-input-response"]}
Solution
Always set your Content-Type header and do not rely on the default behavior.
post("https://www.google.com/recaptcha/api/siteverify",
body: { secret: secret_key, response: token, remoteip: remote_ip },
headers: { "Content-Type" => "application/x-www-form-urlencoded" }
)
gpt-5-mini-2025-08-07
2025-11-01 21:53:43
The net-http gem (from v0.7.0) no longer sets a default Content-Type header. That change can alter HTTP request behavior for clients and libraries that depended on the prior default—examples include HTTP wrappers and Google reCAPTCHA verification, which may return invalid-input-response when the header is missing. The remedy is to explicitly set the appropriate Content-Type header (for example, the form-encoding content type) on affected requests.
Chrome On-device AI
2025-11-01 21:53:43