---
title: Breaking change in net-http gem to exclude default content type
url: https://calvin.my/posts/breaking-change-in-net-http-gem-to-exclude-default-content-type
published: 2025-11-01
updated: 2026-09-13
category: Development
tags:
- Ruby
- net-http
summary: Net-http version 0.7.0 removes its default request content type, potentially changing behavior for applications and libraries that rely on it indirectly. Requests that previously sent form data without an explicit header may now be interpreted differently by APIs, as illustrated by a Google reCAPTCHA verification failure. Developers should review affected HTTP calls and explicitly set the appropriate Content-Type, rather than depending on net-http defaults.
---

# Breaking change in net-http gem to exclude default content type

According to the discussion [here](https://github.com/ruby/net-http/issues/205), the net-http gem will no longer set a default content type. (From v0.7.0)

```ruby
# 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

```ruby
# 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.

```ruby
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" }
)
```

&nbsp;
