480 Commits
Author SHA1 Message Date
Hiroshi SHIBATA bbf5f12331 Use EnvUtil.apply_timeout_scale 2025-04-03 15:32:20 -07:00
Hiroshi SHIBATA 4d6143dd18 Extend open_timeout for test failure on s390x
https://rubyci.s3.amazonaws.com/s390x/ruby-master/log/20250403T060004Z.fail.html.gz
2025-04-03 15:32:20 -07:00
Misaki Shioi fd4b27472e Do not wait connection attempt delay without in progress fds (#12087)
Do not wait Connection Attempt Delay without in progress fds

Reset Connection Attempt Delay when connection fails and there is no other socket connection in progress.
This is intended to resolve an issue that was temporarily worked around in Pull Request #12062.

`TCPServer::new` (used in tests such as `TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write`) can only connect over either IPv6 or IPv4, depending on the environment.
Since HEv2 attempts to connect over IPv6 first, environments where IPv6 connections are unavailable return ECONNREFUSED immediately.
In such cases, the client should immediately retry the connection over IPv4.
However, HEv2 includes a specification for a "Connection Attempt Delay," where it waits 250ms after the previous connection attempt before starting the next one.
This delay causes Net::OpenTimeout (100ms) to be exceeded while waiting for the next connection attempt to start.

With this change, when a connection attempt fails, if there are sockets still attempting to connect and there are addresses yet to be tried, the Connection Attempt Delay will be resetted, allowing the next connection attempt to start immediately.

---

Additionally, the following minor fixes have been made:

- The `nfds` value used for select(2) is now reset with each wait.
2024-11-15 00:25:59 +09:00
Misaki Shioi fee706d9dd Allow Net::HTTP#request to raise Net::OpenTimeout (#12062)
with a TCPSoerver that is only listening
to avoid AssertionFailedError on Ubuntu.

---

The tests such as
`TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write`
expect to raise a `Net::WriteTimeout` due to a failure in writing to the server.

However, on Ubuntu environments,
the server immediately returns a "Connection Refused" in such cases.
The socket created with `TCPSocket.new` that supports HEv2 catches this immediately
and raises a `Net::OpenTimeout`.
As a result, these tests fail due to raising a different exception than expected.
This PR adds `Net::OpenTimeout` asexceptions to avoid these test failures.
2024-11-12 19:14:05 +09:00
Yusuke Endoh 6ae05584bd [ruby/net-http] Prevent warnings
```
/home/chkbuild/chkbuild/tmp/build/20240913T003003Z/ruby/test/net/http/utils.rb:32: warning: assigned but unused variable - e
/home/chkbuild/chkbuild/tmp/build/20240913T003003Z/ruby/test/net/http/utils.rb:61: warning: assigned but unused variable - version
/home/chkbuild/chkbuild/tmp/build/20240913T003003Z/ruby/test/net/http/utils.rb:124: warning: method redefined; discarding old query
```

https://github.com/ruby/net-http/commit/6f818346ce
2024-09-13 02:39:11 +00:00
Nobuyoshi Nakada 30f57637ee Wait for server threads to finish 2024-07-30 07:33:43 +08:00
Hiroshi SHIBATA 83a99bdbe6 [ruby/net-http] Removed needless NullWriter class
https://github.com/ruby/net-http/commit/ddb2a81aed
2024-07-26 01:45:02 +00:00
Hiroshi SHIBATA 2a12e4ffec To avoid fd leak with fetch request for SSL server 2024-07-17 17:37:57 +09:00
Hiroshi SHIBATA f4c642edb1 Fixed fd leak from TCPServer
```
Leaked file descriptor: HTTPSProxyTest#test_https_proxy_ssl_connection: 8 : #<TCPServer:fd 8, AF_INET, 127.0.0.1, 63104>
```
2024-07-17 17:37:57 +09:00
Hiroshi SHIBATA 9acc0efdc1 Use fixture certificates to fix test failure with RHEL9.
http://rubyci.s3.amazonaws.com/rhel9/ruby-master/log/20240711T213004Z.fail.html.gz

```
  1) Error:
HTTPSProxyTest#test_https_proxy_ssl_connection:
OpenSSL::X509::CertificateError: invalid digest
    /home/chkbuild/chkbuild/tmp/build/20240711T213004Z/ruby/test/net/http/test_https_proxy.rb:63:in 'OpenSSL::X509::Certificate#sign'
    /home/chkbuild/chkbuild/tmp/build/20240711T213004Z/ruby/test/net/http/test_https_proxy.rb:63:in 'HTTPSProxyTest#test_https_proxy_ssl_connection'
```
2024-07-12 09:15:12 +09:00
Evgeni Golov bc1b4235fb [ruby/net-http] implement talking SSL to the proxy too
https://bugs.ruby-lang.org/issues/16482

https://github.com/ruby/net-http/commit/ae2d83f88b
2024-07-11 01:56:08 +00:00
fatkodima 70bdc0f777 [ruby/net-http] Add ability to configure default settings for new connections
https://github.com/ruby/net-http/commit/fed3dcd0c2
2024-07-11 01:51:03 +00:00
MSP-Greg 9f4b45fbf7 [ruby/net-http] test_https.rb - fix test_session_reuse_but_expire
https://github.com/ruby/net-http/commit/5544243c41
2024-07-11 01:22:10 +00:00
git 8c69caa495 * append newline at EOF. [ci skip] 2024-07-10 23:06:20 +00:00
Hiroshi SHIBATA 840f7ebfde [ruby/net-http] Commented out unfinished chunked test
https://github.com/ruby/net-http/commit/6376592cb4
2024-07-10 23:06:10 +00:00
Hiroshi SHIBATA 492b505d95 [ruby/net-http] Removed needless warning
https://github.com/ruby/net-http/commit/d867edc0fe
2024-07-10 23:06:10 +00:00
Hiroshi SHIBATA b11aba503b [ruby/net-http] Split POST test because new dummy server can't handle continuouse POST request
https://github.com/ruby/net-http/commit/54a99b9f0c
2024-07-10 23:06:09 +00:00
Hiroshi SHIBATA e77bc17e5d [ruby/net-http] Write log after server start, not handling request
https://github.com/ruby/net-http/commit/205bac757a
2024-07-10 23:06:09 +00:00
Hiroshi SHIBATA 6428536146 [ruby/net-http] Split test class because TCPServer couldn't accept localhost and 127.0.0.1 both
https://github.com/ruby/net-http/commit/749a1b3197
2024-07-10 23:06:08 +00:00
Hiroshi SHIBATA 4e6463ad7a [ruby/net-http] Support chunked data and fixed test failure with multipart/form-data
https://github.com/ruby/net-http/commit/b38c2795a9
2024-07-10 23:06:08 +00:00
Hiroshi SHIBATA 87a45af105 [ruby/net-http] Removed server-side log test
https://github.com/ruby/net-http/commit/9c16c383ce
2024-07-10 23:06:07 +00:00
Hiroshi SHIBATA 5e6f04abc8 [ruby/net-http] Fix wrong hostname with test_max_version test
https://github.com/ruby/net-http/commit/f00d198433
2024-07-10 23:06:07 +00:00
Hiroshi SHIBATA c7eb9ac6f9 [ruby/net-http] Rewrite WEBrick server with TCPServer and OpenSSL::SSL::SSLServer
https://github.com/ruby/net-http/commit/b01bcf6d7f
2024-07-10 23:06:06 +00:00
Xi Ruoyao 03f8477566 [ruby/net-http] Skip test_session_reuse_but_expire with OpenSSL 3.3
OpenSSL 3.3.0 9 Apr 2024 is also broken.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>

https://github.com/ruby/net-http/commit/ab525c956d
2024-04-25 08:01:53 +00:00
NARUSE, Yui 64b6a018a3 Fix test session reuse but expire (#9824)
* OpenSSL 3.2.1 30 Jan 2024 is also broken

Import 4506461072 from ruby_3_3 branch
tentatively.
2024-02-07 10:59:59 +09:00
NARUSE, Yui bc79229be9 Show OpenSSL version in the error message of assert_equal 2024-02-03 19:39:17 +09:00
Jeremy EvansandJeremy Stanley 4d03140009 [ruby/net-http] Don't invoke response block more than once due to retry
If a socket error occurs while performing a streaming download via
the response block provided to transport_request, avoid calling
the response block again as this would result in duplicate data
received by the client.

Fixes https://github.com/ruby/net-http/pull/86
Fixes https://github.com/ruby/net-http/pull/87

Fixes [Bug #11526]

https://github.com/ruby/net-http/commit/114d01b092

Co-authored-by: Jeremy Stanley <jeremy@instructure.com>
2024-01-05 16:51:37 +00:00
Sorah Fukumori d3933fc753 [ruby/net-http] Renew test certificates
The private key is replaced with a public known test key published at
[RFC 9500].

Also lifetime has been extended to 10 years from 4 years.

[RFC 9500]: https://www.rfc-editor.org/rfc/rfc9500.html

https://github.com/ruby/net-http/commit/4ab6c4a500
2024-01-01 11:51:15 +00:00
Nobuyoshi Nakada 1b7376423d Omit test_session_reuse_but_expire if OpenSSL 3.2.0 2023-11-26 01:18:48 +09:00
Takashi Kokubun de37b78050 Omit a broken https test on MinGW
This started to reliably fail on MinGW at an irrelevant commit:
https://github.com/ruby/ruby/actions/runs/6981002841/job/18997302124
https://github.com/ruby/ruby/actions/runs/6981946473/job/19000104223
https://github.com/ruby/ruby/actions/runs/6983823136/job/19005613809
https://github.com/ruby/ruby/actions/runs/6983912116/job/19005844596
https://github.com/ruby/ruby/actions/runs/6984215921/job/19006649495
https://github.com/ruby/ruby/actions/runs/6984383103/job/19007100446
https://github.com/ruby/ruby/actions/runs/6986489509/job/19012000642

So this failure is not detecting a new bug. Let's skip this until we fix
this test for MinGW.
2023-11-24 21:43:34 -08:00
Christian van Rensen f109269a03 [ruby/net-http] fix a false-negative test
* no_proxy is meant to operate on the destination address, not on the name of the proxy
* if both end with `'.example'`, the test does not nail down the behaviour

https://github.com/ruby/net-http/commit/bb9a5cfa3d
2023-10-30 09:27:06 +00:00
Jeremy Evans 3dec5dc346 [ruby/net-http] Force TLS version to 1.2 when using LibreSSL
This comment previously specified TLS 1.2, but actually set the
version to TLS 1.0.  LibreSSL 3.8.1 (included in OpenBSD 7.4)
dropped support for TLS 1.0/1.1 for security reasons, which
broke this test.  Switch the test to use TLS 1.2 as documented
so it will continue to work on OpenBSD 7.4+.

https://github.com/ruby/net-http/commit/97be4de53a
2023-10-16 20:23:50 +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
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
Hiroshi SHIBATA 9557c8edf2 Merge net-protocol-0.2.1 2022-12-09 16:36:22 +09:00
Jean Boussier 6081fd4564 [ruby/net-protocol] Failing test case for #19
Unfortunately we have to use a mock, but this test demonstrate the
mutation bug fixed in #19.

It fails on 0.2.0 but passes on 0.1.3 or 0.2.1.

https://github.com/ruby/net-protocol/commit/40a1ab687c
2022-12-08 12:15:52 +00:00
Peter Zhu de9e2a5ac7 [ruby/net-http] Fix test for Ruby head
The error raised for broken coderanges was changed in ruby/ruby@571d21f
and the test was fixed in that commit but not ported to this repo.

ruby/net-http@e6185dda26
2022-11-26 16:06:05 -05:00
Jeremy Evans 571d21fd4a Make String#rstrip{,!} raise Encoding::CompatibilityError for broken coderange
It's questionable whether we want to allow rstrip to work for strings
where the broken coderange occurs before the trailing whitespace and
not after, but this approach is probably simpler, and I don't think
users should expect string operations like rstrip to work on broken
strings.

In some cases, this changes rstrip to raise
Encoding::CompatibilityError instead of ArgumentError.  However, as
the problem is related to an encoding issue in the receiver, and due
not due to an issue with an argument, I think
Encoding::CompatibilityError is the more appropriate error.

Fixes [Bug #18931]
2022-11-24 18:24:42 -08:00
Jeremy Evans cd77e71bba [ruby/net-http] Remove ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
This list is out of date.  At least OpenBSD since 2013 does not
allow one user to read the environment variables of a process
run by another user.

While we could try to keep the list updated, I think it's a bad
idea to not use the user/password from the environment, even if
another user on the system could read it.  If http_proxy exists
in the environment, and other users can read it, it doesn't
make it more secure for Ruby to ignore it.  You could argue that
it encourages poor security practices, but net/http should provide
mechanism, not policy.

Fixes [Bug #18908]

https://github.com/ruby/net-http/commit/1e4585153d
2022-09-28 17:26:03 +09:00
Shishir JoshiandNobuyoshi Nakada c310691dd8 [ruby/net-http] Make Net::HTTPHeader#content_range return nil on non-byte units
* Returning nil from the `content_range` method instead of raising an
  error when the unit in the content-range header is not "bytes".

Fix https://bugs.ruby-lang.org/issues/11450

https://github.com/ruby/net-http/commit/0b5030dd86

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-06-16 23:35:27 +09:00
Nobuyoshi Nakada 2223eb082a Revert "HTTPHeader.content_range throws error on non-byte units"
This reverts commit 63546bfc15.
2022-06-16 22:10:59 +09:00
Shishir Joshi 63546bfc15 HTTPHeader.content_range throws error on non-byte units
* Added a nil check in Net::HTTPHeader#initialize_http_header for keys in the header that do not have any value
* Returning nil from the content_range method instead of raising an error when the unit in the content-range header is not bytes
* Modified initialize_http_header to match trunk

fix [Bug #11450]
fix https://github.com/ruby/ruby/pull/1018
2022-06-16 20:16:47 +09:00
Karol Bucek cf73cf5981 [ruby/net-http] Feature detect to make net/http usable with JRuby
Handle missing session_new_cb= and do not call
session_cache_mode=, as JRuby SSL does not support
these methods.

https://github.com/ruby/net-http/commit/3237ef4d8c
2022-04-20 13:01:08 +09:00
Jeremy Evans 90ccc5674a [ruby/net-http] Add ignore_eof access to HTTP and HTTPResponse
The ignore_eof setting on HTTPResponse makes it so an EOFError is
raised when reading bodies with a defined Content-Length, if the
body read was truncated due to the socket be closed.

The ignore_eof setting on HTTP sets the values used in responses
that are created by the object.

For backwards compatibility, the default is for both settings is
true.  However, unless you are specifically tested for and handling
truncated responses, it's a good idea to set ignore_eof to false so
that errors are raised for truncated responses, instead of those
errors silently being ignored.

Fixes [Bug #14972]

https://github.com/ruby/net-http/commit/4d47e34995
2022-04-20 10:22:06 +09:00
Jeremy Evansandst0012 0579486f15 [ruby/net-http] Update the content-length heading when decoding bodies
Previously, the content-encoding header was removed and the body
was modified, but the content-length header was not modified,
resulting in the content-length header not matching the body
length.

Don't delete content-length before yielding inflate body, as that
causes a switch to read the entire body instead of reading in
chunks.

Fixes [Bug #16672]

https://github.com/ruby/net-http/commit/58284e9710

Co-authored-by: st0012 <stan001212@gmail.com>
2022-04-14 00:11:26 +09:00
Jeremy EvansandYui Naruse ebb4378237 [ruby/net-http] Add HTTP#response_body_encoding for setting response body encoding
This allows for the ability to opt-in to a method to set the
encoding of response bodies.  By setting the accessor to a String
or Encoding instance, it will use the specified encoding.
Setting the value of true will try to detect the encoding of the
response body, either using the Content-Type header (assuming it
specifies charset) or by scanning for a <meta> tag in the document
that specifies the encoding.  The default is false in which case
no forcing of encoding will be done (same as before the patch).

Implements [Feature #2567]
Implements [Feature #15517]

https://github.com/ruby/net-http/commit/6233e6b7c1

Co-authored-by: Yui Naruse <naruse@ruby-lang.org>
2022-04-12 00:17:34 +09:00
Jeremy Evans 7648bae4c8 [ruby/net-http] Revert "Update the content-length heading when decoding bodies"
This reverts commit https://github.com/ruby/net-http/commit/a7cb30124cf1.

This is causing errors in Ruby's CI, will revert for now and
try again after testing a fix with Ruby's CI.

https://github.com/ruby/net-http/commit/7b852b1feb
2022-04-03 06:51:07 +09:00
Jeremy Evans 58adb1636b [ruby/net-http] Update the content-length heading when decoding bodies
Previously, the content-encoding header was removed and the body
was modified, but the content-length header was not modified,
resulting in the content-length header not matching the body
length.

Fixes [Bug #16672]

https://github.com/ruby/net-http/commit/a7cb30124c
2022-04-02 02:49:21 +09:00
Jeremy Evans 7529c53891 [ruby/net-http] Do not set SNI hostname if connecting to IP address
RFC 6066, section 3, explicitly disallows the use of an IP address
as an SNI server name.  So check if the connection is being made
to an IP address using the resolv regexps, and do not set an SNI
hostname in that case.

Recent changes to LibreSSL make it more strictly follow RFC 6066,
resulting an s.hostname= raising an error if passed an IP address.
When such verions of LibreSSL are used, this change not only fixes
the net/http tests, it also fixes tests for webrick and open-uri,
which both make SSL connections to 127.0.0.1 using net/http in
their tests.

Avoid warning in the openssl extension by unsetting
@ssl_context.verify_hostname if connecting to an IP address.
Make changes so that the post_connection_check still happens
when connecting to an IP address, which is necessary to keep
checking that the certificate returned includes the IP address,
which one of the tests depends on.

Revert the previous change that modified the regexp used for
checking the error message.

https://github.com/ruby/net-http/commit/fa68e64bee
2022-02-03 05:10:21 +09:00