193 Commits
Author SHA1 Message Date
Sutou Kouhei b45655470c [ruby/net-http] Treat a whitespace-only header line as obs-fold
(https://github.com/ruby/net-http/pull/348)

The current implementation has a problem with the following case:

```ruby
print("HTTP/1.1 200 OK\r\n")
print("Content-Length: 5\r\n")
print(" \t\r\n")
print("X-After: value\r\n")
print("\r\n")
print("hello")
```

The `" \t\r\n"` line should be processed as obs-fold in RFC 9112:

https://www.rfc-editor.org/rfc/rfc9112.html#section-5.2

>     obs-fold     = OWS CRLF RWS
>                  ; obsolete line folding
>
>     A user agent that receives an obs-fold in a response message that
>     is not within a "message/http" container MUST replace each received
>     obs-fold with one or more SP octets prior to interpreting the field
>     value.

But it's processed as the header part end:

Header:

```text
HTTP/1.1 200 OK
Content-Length: 5
```

Body:

```text
X-After: value

hello
```

It must be processed as the following (whitespace only obs-fold is
ignored):

Header:

```text
HTTP/1.1 200 OK
Content-Length: 5
X-After: value
```

Body:

```text
hello
```

https://github.com/ruby/net-http/commit/6e2bc82919
2026-10-06 23:37:25 +00:00
Hiroshi SHIBATAandClaude Opus 5 4eb03b31cb [ruby/net-http] Let Transfer-Encoding override Content-Length
Once chunked is not the final transfer coding, read_body_0 fell through
to Content-Length and framed the body by it, which leaves the client and
the server disagreeing about where the response ends.

See RFC 9112 Section 6.3:
https://www.rfc-editor.org/rfc/rfc9112.html#section-6.3

    If a message is received with both a Transfer-Encoding and a
    Content-Length header field, the Transfer-Encoding overrides the
    Content-Length.

https://github.com/ruby/net-http/commit/9fb5b93b52

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 02:55:16 +00:00
Hiroshi SHIBATAandClaude Opus 5 21bc49cf73 [ruby/net-http] Require chunked to be the final transfer coding
Net::HTTPHeader#chunked? matched the token anywhere in
Transfer-Encoding, so a response carrying `chunked, gzip` was
chunk-framed and the bytes after the terminating chunk were left
unread on the connection.

See RFC 9112 Section 6.3:
https://www.rfc-editor.org/rfc/rfc9112.html#section-6.3

    If a Transfer-Encoding header field is present in a response and
    the chunked transfer coding is not the final encoding, the message
    body length is determined by reading the connection until it is
    closed by the server.

https://github.com/ruby/net-http/commit/e70762aaf9

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 02:55:16 +00:00
Sutou Kouhei 2c260b8dec [ruby/net-http] Make Content-Length handling strict
(https://github.com/ruby/net-http/pull/324)

`Content-Length` value must have only digits.

See also RFC 9110 Section 8.6:
https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6

    Content-Length = 1*DIGIT

The current implementation accepts garbage before/after digits such as
`abc5` and `5abc`.

This rejects these invalid values.

But this accepts same values in one `Content-Length`

    Content-Length: 5, 5

and in multiple `Content-Length`es:

    Content-Length: 5
    Content-Length: 5

This is for the following part in the RFC:

https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6-13

> Likewise, a sender MUST NOT forward a message with a Content-Length
> header field value that does not match the ABNF above, with one
> exception: a recipient of a Content-Length header field value
> consisting of the same decimal value repeated as a comma-separated
> list (e.g, "Content-Length: 42, 42") MAY either reject the message
> as invalid or replace that invalid field value with a single
> instance of the decimal value, since this likely indicates that a
> duplicate was generated or combined by an upstream message
> processor.

https://github.com/ruby/net-http/commit/23e859e92e
2026-08-26 00:46:26 +00:00
Hiroshi SHIBATAandClaude Opus 5 05e1f1f648 [ruby/net-http] Limit the number of informational responses per request
A peer that keeps sending 1xx responses keeps the client in the read
loop of transport_request indefinitely, since the per-response header
limit resets for each response. Cap the count at 100, the same value
CPython's http.client uses.

https://github.com/ruby/net-http/commit/39cf5f648a

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 00:33:27 +00:00
Hiroshi SHIBATAandClaude Fable 5 331568b2a9 [ruby/net-http] Limit read length of a single response line
The response header cap added by #219 applies only once a complete line
has arrived, so a server that never sends a line terminator can still
grow the read buffer without bound, as reported in #315. Read the
status line, header lines, chunk-size lines and chunk trailers through
net-protocol's readuntil(limit:) so they fail with
Net::HTTPBadResponse at MAX_RESPONSE_HEADER_LENGTH, and require the
net-protocol that provides it.

The cumulative header budget stays separate from the per-line limit so
that exhausting the total still reports 'response header too large'
rather than blaming a line that is not long.

https://github.com/ruby/net-http/issues/315

https://github.com/ruby/net-http/commit/132c8cc1b1

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-25 23:13:17 +00:00
Sean Doyle 59d4afaade [ruby/net-http] Add support for HTTP QUERY method
Closes https://github.com/ruby/net-http/issues/202

As of June 2026, [RFC 10008][] is a proposed standard.

From the RFC Abstract:

> This specification defines the QUERY method for HTTP. A QUERY requests
> that the request target process the enclosed content in a safe and
> idempotent manner and then respond with the result of that processing.
> This is similar to POST requests, but QUERY requests can be
> automatically repeated or restarted without concern for partial state
> changes.

This commit proposes support for the HTTP Query method by way of the
`Net::HTTP::Query` class along with the corresponding `#query` and
`#request_query` methods.

[RFC 10008]: https://www.rfc-editor.org/rfc/rfc10008.html

https://github.com/ruby/net-http/commit/76b11b3a26
2026-07-10 03:29:36 +00:00
5900b2f53d [ruby/net-http] Limit the total size of response headers
each_response_header read header lines until the blank separator with no
bound on their total size, so a server could exhaust client memory by
sending a large header block. Cap the cumulative size at 1 MiB and raise
Net::HTTPBadResponse once it is exceeded.

https://github.com/ruby/net-http/commit/ebe8f3876f

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 16:02:15 +09:00
6f3e462182 [ruby/net-http] Validate header key and field value length in set_field
The length limits only ran in initialize_http_header, which responses
bypass: each_response_header builds the response through add_field and
set_field, so an oversized response header field was never bounded. Check
the field value length in set_field and append_field_value, and fold the
key length check into validate_field_name so set_field and
initialize_http_header share one place for validating field names.

https://github.com/ruby/net-http/commit/ab084fdc0c

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 16:02:15 +09:00
Hiroshi SHIBATAandClaude Fable 5 fce7fb63fc [ruby/net-http] Reject CR/LF in multipart boundary
A custom boundary is interpolated into the part separators as-is, so a
boundary containing CR/LF could forge part headers in the same way as
the field name and filename.

https://github.com/ruby/net-http/commit/44c480b336

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 01:50:53 +00:00
Hiroshi SHIBATAandClaude Fable 5 bb4b4f1fdf [ruby/net-http] Coerce multipart content type to a string before validating
The CR/LF check via Regexp#match? requires a String, but the per-part
content type was previously interpolated through to_s and accepted any
object such as a Symbol. Coerce it first to keep that behavior.

https://github.com/ruby/net-http/commit/c07d6581ce

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 01:50:53 +00:00
Hiroshi SHIBATAandClaude Fable 5 94c133a368 [ruby/net-http] Reject CR/LF in multipart field name, filename, and content type
encode_multipart_form_data interpolated the field name, filename, and
per-part content type into Content-Disposition and Content-Type lines
with only quote_string escaping backslash and double quote, so CR/LF in
any of them could forge part headers and tamper with the request.

Fixes https://github.com/ruby/net-http/issues/195

https://github.com/ruby/net-http/commit/02a962fce2

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 01:50:53 +00:00
Hiroshi SHIBATAandClaude Fable 5 cb8a34d785 [ruby/net-http] Validate Content-Type value set by set_content_type
set_content_type assigned to @header directly, bypassing the CR/LF
validation in set_field, so a crafted media type or parameter could
inject header lines.

https://github.com/ruby/net-http/commit/5fe0f96190

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 01:50:53 +00:00
Hiroshi SHIBATAandClaude Fable 5 ebddeca11d [ruby/net-http] Reject control characters and colon in header field names
Field values and the request line are already validated against CR/LF,
but field names were interpolated into the request as-is, allowing
header injection via the key. Validate names in set_field and
initialize_http_header, which cover all paths into @header with a
user-supplied key.

https://github.com/ruby/net-http/commit/4f13ea5047

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 01:50:53 +00:00
Erik Berlin 2602e3a9b6 [ruby/net-http] Add existing RBS interface tests from ruby/rbs repo
https://github.com/ruby/net-http/commit/2842ca5539
2026-03-17 08:52:13 +00:00
BurdetteLamar 40e3e43b93 [ruby/net-http] [DOC] Fix links in requests.rb
https://github.com/ruby/net-http/commit/a232aea2fc
2026-01-29 05:02:36 +00:00
Taketo Takashima 1d903b727f [ruby/net-http] Drop support for Ruby 2.6
https://github.com/ruby/net-http/commit/a3a5bc45f6
2025-11-13 14:33:22 +00:00
2ab21f56f9 [ruby/net-http] Fix handling of IPv6 literal hosts in Net::HTTPGenericRequest
Update uri dependency to version 0.11.0 or later to use `URI::HTTP#authority` and `URI#parse` without scheme

https://github.com/ruby/net-http/commit/3d4f06bd7f

Co-authored-by: 0x1eef <0x1eef@users.noreply.github.com>
Co-authored-by: Sorah Fukumori <sora134@gmail.com>
2025-11-13 14:33:22 +00:00
Nobuyoshi Nakada 3147df87ba [ruby/net-http] [DOC] Suppress documentation for internals
https://github.com/ruby/net-http/commit/b7c586985a
2025-11-10 03:38:04 +00:00
Nobuyoshi Nakada 4fe0342a86 Reapply "[ruby/net-http] [DOC] Suppress documentation for internals"
This reverts commit af610e107c.
Reverted by a mistake.
2025-11-09 22:18:37 +09:00
Nobuyoshi Nakada af610e107c Revert "[ruby/net-http] [DOC] Suppress documentation for internals"
This reverts commit 155cdce539.
2025-11-09 22:11:40 +09:00
Nobuyoshi Nakada 155cdce539 [ruby/net-http] [DOC] Suppress documentation for internals
https://github.com/ruby/net-http/commit/e4d80bd609
2025-11-09 21:06:24 +09:00
Nobuyoshi Nakada 001890b851 [ruby/net-http] Exclude unneeded files
https://github.com/ruby/net-http/commit/89e1ecb556
2025-11-09 21:06:23 +09:00
Nobuyoshi Nakada 51118fa2da [ruby/net-http] Support pretty_print
https://github.com/ruby/net-http/commit/bfc60454f6
2025-06-11 05:04:16 +00:00
Hiroshi SHIBATA 51b70d106a [ruby/net-http] Don't set content type by default
Fixes https://github.com/ruby/net-http/issues/205

https://github.com/ruby/net-http/commit/002441da1e
2025-06-11 03:35:11 +00:00
Daisuke Aritomo aa0f689bf4 [ruby/net-http] Freeze some constants to improve Ractor compatibility
Freeze `Net::HTTP::SSL_IVNAMES`, `Net::HTTPResponse::CODE_CLASS_TO_OBJ`
and `Net::HTTPResponse::CODE_TO_OBJ` to improve Ractor compatibility.

This change allows the following code to work:

    Ractor.new {
      uri = URI.parse('http://example.com')
      http = Net::HTTP.new(uri.host, uri.port)
      http.open_timeout = nil
      http.read_timeout = nil
      http.get('/index.html')
    }

https://github.com/ruby/net-http/commit/9f0f5e4b4d
2025-05-17 00:42:12 +00:00
Mark Young 80b01cc567 [ruby/net-http] Provide a 'Changelog' link on rubygems.org/gems/net-http
By providing a 'changelog_uri' in the metadata of the gemspec a
'Changelog' link will be shown on https://rubygems.org/gems/net-http
which makes it quick and easy for someone to check on the changes
introduced with a new version.

Details of this functionality can be found on https://guides.rubygems.org/specification-reference/#metadata

https://github.com/ruby/net-http/commit/eeb728fefe
2025-01-06 01:19:55 +00:00
Nobuyoshi Nakada 8e98fbdd19 [ruby/net-http] Remove deprecated constants
These constants, isolated in net/http/backward.rb, have not only been
deprecated since 2001, but have also had a warning since 2021.

https://github.com/ruby/net-http/commit/265bfa929f
2024-11-15 03:15:04 +00:00
Brandon WeaverandJean Boussier bc6860db23 [ruby/net-http] Update lib/net/http/header.rb
https://github.com/ruby/net-http/commit/826e008cfe

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-05-30 09:16:15 +00:00
Brandon Weaver 4839493f3f [ruby/net-http] Replace Regexp in for headers for perf
https://github.com/ruby/net-http/commit/15f1349e4e
2024-05-30 09:16:15 +00:00
Zopolis4 4d744a7aa7 [ruby/net-http] Add Net::HTTP.put method
https://github.com/ruby/net-http/commit/6dc01c985b
2024-05-30 09:02:32 +00:00
Brian Hawley 9d58f93828 [ruby/net-http] Net::HTTPResponse nil checking
Fix nil handling in read_body and stream_check.

Fixes: #70

https://github.com/ruby/net-http/commit/36f916ac18
2023-10-05 07:11:52 +00:00
0x1eef e77c766b7a [ruby/net-http] No longer neccessary to call String#freeze on string literals.
See #144

https://github.com/ruby/net-http/commit/5a986c13d3
2023-09-19 01:32:18 +00:00
Josh NicholsandNate Matykiewicz ae68a8df58 [ruby/net-http] Update lib/net/http/response.rb
@natematykiewicz's suggestion to avoid a string allocation

https://github.com/ruby/net-http/commit/925630f227

Co-authored-by: Nate Matykiewicz <natematykiewicz@gmail.com>
2023-08-16 01:40:12 +00:00
Josh Nichols ea321a654d [ruby/net-http] use +'' everywhere
https://github.com/ruby/net-http/commit/1077427152
2023-08-16 01:40:11 +00:00
Josh Nichols 4d21134f3f [ruby/net-http] freeze rest of lib
https://github.com/ruby/net-http/commit/455a74734a
2023-08-16 01:40:09 +00:00
Josh Nichols 4165ec91d8 [ruby/net-http] update net/http/response to be frozen string literal
https://github.com/ruby/net-http/commit/dc3b4a75ca
2023-08-16 01:40:08 +00:00
Josh Nichols 2fbd8dca18 [ruby/net-http] turn on frozen strings for net/http/generic_request
https://github.com/ruby/net-http/commit/b92ade088d
2023-08-16 01:40:08 +00:00
Josh Nichols 8d04260acd [ruby/net-http] turn on frozen strings for net/http/header
https://github.com/ruby/net-http/commit/a5203c9f92
2023-08-16 01:40:07 +00:00
Josh Nichols 0300ea5a6c [ruby/net-http] Improve performance of HTTPHeader#content_type
In the existing implementation, `main_type` and `sub_type` would end up
being called multiple times potentially.

Instead of doing that, save the result so it can be re-used.

https://github.com/ruby/net-http/commit/179976f7ea
2023-08-16 01:39:08 +00:00
Nobuyoshi Nakada cfa6a892d0 Redirect to IO::NULL for the portability 2023-05-05 18:52:36 +09:00
Hiroshi SHIBATA bc0a7a641b [ruby/net-http] typofix
https://github.com/ruby/net-http/commit/4d31bde125
2023-03-31 03:47:56 +00:00
NAKAMURA Usaku eedcd696a5 [ruby/net-http] Fix previous commit
https://github.com/ruby/net-http/commit/1b276e2654
2023-03-31 03:22:41 +00:00
NAKAMURA Usaku d8b8294c28 [ruby/net-http] Limit header length
https://github.com/ruby/net-http/commit/c245f7f9c8
2023-03-31 03:22:40 +00:00
Burdette Lamar 2f19c5b7e0 [ruby/net-http] Enhanced RDoc for Net::HTTP
(https://github.com/ruby/net-http/pull/130)

https://github.com/ruby/net-http/commit/698e18cfc1
2023-03-08 19:47:49 +00:00
Nobuyoshi Nakada 755c379d87 [ruby/net-http] Exclude git related files
https://github.com/ruby/net-http/commit/2767df580d
2023-03-06 13:26:36 +00:00
Nobuyoshi Nakada c8c3431b0a [ruby/net-http] Read in binary mode to get rid of invalid byte sequence
https://github.com/ruby/net-http/commit/38de3d17a7
2023-03-06 13:26:34 +00:00
Hiroshi SHIBATA 9cc0ac22f7 Update lib/net/http/status.rb 2023-02-28 14:29:57 +09:00
Hiroshi SHIBATA db0a4c8923 Prefer to use File.foreach instead of IO.foreach 2023-02-27 18:49:18 +09:00
Burdette Lamar 05f016cdad [ruby/net-http] [DOC] Enhanced RDoc for Net::HTTP
(https://github.com/ruby/net-http/pull/126)

https://github.com/ruby/net-http/commit/4700d0660b
2023-02-24 19:09:06 +00:00