サンプル
faraday-net_http 3.4.4: Handle input domain edge cases in faraday-net_http including zero-value timeout truthiness, proxy URI credential stripping, and method case sensitivity
検証済みサンプル — gem faraday-net_http 3.4.4: Handle input domain edge cases in faraday-net_http including zero-value timeout truthiness, proxy URI credential…
sha256:e668d3939be32bcc4025992632f9fe80e4deafc0671e490a16ae14f95099d26d
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 2
宣言された環境
ruby linux x64 ruby ruby rubygems
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-17 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-18 |
ケース
HOW- ゴール
- Handle input domain edge cases in faraday-net_http including zero-value timeout truthiness, proxy URI credential stripping, and method case sensitivity
- パッケージ
- シンボル
-
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttp#build_connection
- Faraday::Adapter::NetHttp#net_http_connection
- Faraday::Adapter::NetHttp#configure_request
- Faraday::Adapter::NetHttp#create_request
- 環境
- ruby
- 作成日
- 2026-08-17T02:42:12Z
コントラクト
- Setting request timeout to 0 configures Net::HTTP read, open, and write timeouts to 0 seconds rather than disabling timeouts or falling back to defaults because 0 is truthy in Ruby.
- Passing proxy credentials inside the proxy URI object leaves Net::HTTP proxy_user and proxy_pass as nil unless explicitly set in top-level proxy option keys.
- Setting a specific read_timeout of 0 overrides a broader timeout fallback of 10 seconds rather than falling back to 10.
- Passing a method of :HEAD as an uppercase symbol or string sets Net::HTTPGenericRequest response_body_permitted to true because the adapter checks only lowercase symbol :head.
- Omitting proxy configuration passes an explicit nil proxy argument to Net::HTTP.new, disabling automatic ENV proxy inheritance.
- Parsing an IPv6 literal URL extracts the bracketless address ::1 for Net::HTTP connection creation.
ファイル
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- test/contract.rb
ソース
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'faraday', '~> 2.14'
gem 'faraday-net_http', '~> 3.4'
GEM
remote: https://rubygems.org/
specs:
faraday (2.14.3)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.4)
net-http (~> 0.5)
json (2.21.2)
logger (1.7.0)
net-http (0.9.1)
uri (>= 0.11.1)
uri (1.1.1)
PLATFORMS
ruby
x64-mingw-ucrt
DEPENDENCIES
faraday (~> 2.14)
faraday-net_http (~> 3.4)
CHECKSUMS
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
faraday (2.14.3) sha256=1882247e6766615c8220b4392bf1d27f6ebb63d8e28267587cef1fb0bf37f278
faraday-net_http (3.4.4) sha256=0e78af151747ed1b00f33e25973b4bc220d7f16c00c39676817c8b12331eb588
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
net-http (0.9.1) sha256=25ba0b67c63e89df626ed8fac771d0ad24ad151a858af2cc8e6a716ca4336996
uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
BUNDLED WITH
4.0.18
# Notes
### What search_known_solution answered
`search_known_solution` for `pkg:gem/faraday-net_http` with queries on timeout falsiness and proxy URI credential resolution returned compatible matches for different goals (`sha256:3b76bde8027d68317cf0431a765f0a2fc72660ba193915be2347e56abd632d13` on block options vs hash options, `sha256:ff98862d1f5a38ed19d00c8029788fb31dc64d355f52329873c75e52a6539e69` on hostless URIs, and `sha256:433adef28fe1437eec97938d51ac23888970243b093b96201d673f77b3ebdb72` on OpenTimeout vs ReadTimeout exception mapping). This sample addresses input domain boundaries: zero-value timeout truthiness in Net::HTTP socket options, credential loss when proxy authentication is embedded in URI objects rather than top-level hash keys, and uppercase method symbols on HEAD body permission.
### How the wrong version fails
Fails silently with a green build: passing a zero timeout (`timeout: 0`) silently converts standard 60-second timeouts into 0-second instant timeouts across read, open, and write phases rather than disabling timeouts, passing embedded proxy URI credentials silently transmits unauthenticated proxy requests leaving `proxy_user` as `nil`, and passing `:HEAD` or `'HEAD'` silently enables `response_body_permitted` on `Net::HTTPGenericRequest`.
{"case":{"believed":"Setting a request timeout of 0 or passing proxy credentials inside the URI object disables timeouts and authenticates the proxy connection in Faraday's Net::HTTP adapter.","caseId":"case:sha256:541e9520e32ff498985a2d868223aa4aa6bfde1644bb2f4bce775ff3bd2f1120","contract":["Setting request timeout to 0 configures Net::HTTP read, open, and write timeouts to 0 seconds rather than disabling timeouts or falling back to defaults because 0 is truthy in Ruby.","Passing proxy credentials inside the proxy URI object leaves Net::HTTP proxy_user and proxy_pass as nil unless explicitly set in top-level proxy option keys.","Setting a specific read_timeout of 0 overrides a broader timeout fallback of 10 seconds rather than falling back to 10.","Passing a method of :HEAD as an uppercase symbol or string sets Net::HTTPGenericRequest response_body_permitted to true because the adapter checks only lowercase symbol :head.","Omitting proxy configuration passes an explicit nil proxy argument to Net::HTTP.new, disabling automatic ENV proxy inheritance.","Parsing an IPv6 literal URL extracts the bracketless address ::1 for Net::HTTP connection creation."],"goal":"Handle input domain edge cases in faraday-net_http including zero-value timeout truthiness, proxy URI credential stripping, and method case sensitivity","kind":"HOW","packages":["pkg:gem/faraday-net_http@3.4.4"],"schemaVersion":1,"symbols":["Faraday::Adapter::NetHttp","Faraday::Adapter::NetHttp#build_connection","Faraday::Adapter::NetHttp#net_http_connection","Faraday::Adapter::NetHttp#configure_request","Faraday::Adapter::NetHttp#create_request"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"rubygems","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/faraday-net_http@3.4.4"],"schemaVersion":1,"symbols":["Faraday::Adapter::NetHttp","Faraday::Adapter::NetHttp#build_connection","Faraday::Adapter::NetHttp#net_http_connection","Faraday::Adapter::NetHttp#configure_request","Faraday::Adapter::NetHttp#create_request"],"verifierAdapter":"rubygems@1"}
# frozen_string_literal: true
require 'faraday'
require 'faraday/net_http'
require 'uri'
adapter = Faraday::Adapter::NetHttp.new
# ---------------------------------------------------------------------------
# 1. Zero timeout vs nil timeout truthiness in configure_request
# ---------------------------------------------------------------------------
# Setting timeout = 0 sets all timeouts (read, open, write) to 0 seconds (instant timeout)
# because 0 is truthy in Ruby, whereas nil leaves default 60s untouched.
req_zero = Faraday::RequestOptions.new.tap { |o| o.timeout = 0 }
env_zero = Faraday::Env.new(:get, nil, URI('http://example.test'), req_zero, {}, nil, nil)
http_zero = adapter.send(:build_connection, env_zero)
raise "Expected read_timeout to be 0 when timeout = 0, got #{http_zero.read_timeout}" unless http_zero.read_timeout == 0
raise "Expected open_timeout to be 0 when timeout = 0, got #{http_zero.open_timeout}" unless http_zero.open_timeout == 0
raise "Expected write_timeout to be 0 when timeout = 0, got #{http_zero.write_timeout}" unless http_zero.write_timeout == 0
# Setting read_timeout = 0 with general timeout = 10 keeps read_timeout at 0 (0 is truthy in 0 || 10)
req_override = Faraday::RequestOptions.new.tap { |o| o.read_timeout = 0; o.timeout = 10 }
env_override = Faraday::Env.new(:get, nil, URI('http://example.test'), req_override, {}, nil, nil)
http_override = adapter.send(:build_connection, env_override)
raise "Expected read_timeout to be 0, got #{http_override.read_timeout}" unless http_override.read_timeout == 0
raise "Expected open_timeout to be 10, got #{http_override.open_timeout}" unless http_override.open_timeout == 10
raise "Expected write_timeout to be 10, got #{http_override.write_timeout}" unless http_override.write_timeout == 10
# Unset timeouts (nil) preserve default Net::HTTP 60s timeouts
req_nil = Faraday::RequestOptions.new
env_nil = Faraday::Env.new(:get, nil, URI('http://example.test'), req_nil, {}, nil, nil)
http_nil = adapter.send(:build_connection, env_nil)
raise "Expected default read_timeout to remain 60, got #{http_nil.read_timeout}" unless http_nil.read_timeout == 60
raise "Expected default open_timeout to remain 60, got #{http_nil.open_timeout}" unless http_nil.open_timeout == 60
# ---------------------------------------------------------------------------
# 2. Proxy credentials embedded in URI vs top-level keys
# ---------------------------------------------------------------------------
# Passing a URI with embedded credentials (user:pass@host) in proxy[:uri] leaves
# proxy_user and proxy_pass as nil because net_http_connection reads proxy[:user]
proxy_uri = URI::HTTP.build(
userinfo: 'proxy_user:proxy_pass',
host: 'proxy.example.test',
port: 8080
)
env_proxy_uri = Faraday::Env.new(
:get, nil, URI('http://example.test'),
Faraday::RequestOptions.new.tap { |o| o.proxy = { uri: proxy_uri } },
{}, nil, nil
)
http_proxy_uri = adapter.net_http_connection(env_proxy_uri)
raise "Expected proxy_user to be nil when not in top-level hash keys, got #{http_proxy_uri.proxy_user}" unless http_proxy_uri.proxy_user.nil?
raise "Expected proxy_pass to be nil when not in top-level hash keys, got #{http_proxy_uri.proxy_pass}" unless http_proxy_uri.proxy_pass.nil?
raise "Expected proxy_address to be proxy.example.test" unless http_proxy_uri.proxy_address == 'proxy.example.test'
raise "Expected proxy_port to be 8080" unless http_proxy_uri.proxy_port == 8080
# Explicit top-level keys correctly configure Net::HTTP proxy credentials
env_proxy_explicit = Faraday::Env.new(
:get, nil, URI('http://example.test'),
Faraday::RequestOptions.new.tap { |o| o.proxy = { uri: proxy_uri, user: 'proxy_user', password: 'proxy_pass' } },
{}, nil, nil
)
http_proxy_explicit = adapter.net_http_connection(env_proxy_explicit)
raise "Expected proxy_user to be proxy_user" unless http_proxy_explicit.proxy_user == 'proxy_user'
raise "Expected proxy_pass to be proxy_pass" unless http_proxy_explicit.proxy_pass == 'proxy_pass'
# ---------------------------------------------------------------------------
# 3. HTTP method case sensitivity on response body permission in create_request
# ---------------------------------------------------------------------------
# create_request evaluates env[:method] != :head to permit response body.
# Lowercase symbol :head sets response_body_permitted? to false
env_head_sym = Faraday::Env.new(:head, nil, URI('http://example.test'), Faraday::RequestOptions.new, {}, nil, nil)
req_head_sym = adapter.send(:create_request, env_head_sym)
raise "Expected response_body_permitted? to be false for :head" if req_head_sym.response_body_permitted?
# Uppercase symbol :HEAD or string 'HEAD' sets response_body_permitted? to true (:HEAD != :head is true)
env_head_upper = Faraday::Env.new(:HEAD, nil, URI('http://example.test'), Faraday::RequestOptions.new, {}, nil, nil)
req_head_upper = adapter.send(:create_request, env_head_upper)
raise "Expected response_body_permitted? to be true for :HEAD" unless req_head_upper.response_body_permitted?
env_head_str = Faraday::Env.new('HEAD', nil, URI('http://example.test'), Faraday::RequestOptions.new, {}, nil, nil)
req_head_str = adapter.send(:create_request, env_head_str)
raise "Expected response_body_permitted? to be true for 'HEAD'" unless req_head_str.response_body_permitted?
# ---------------------------------------------------------------------------
# 4. Explicit nil proxy suppresses implicit ENV proxy inheritance
# ---------------------------------------------------------------------------
env_no_proxy = Faraday::Env.new(:get, nil, URI('http://example.test'), Faraday::RequestOptions.new, {}, nil, nil)
http_no_proxy = adapter.net_http_connection(env_no_proxy)
raise "Expected proxy? to be false" if http_no_proxy.proxy?
raise "Expected proxy_from_env? to be false due to explicit nil argument" if http_no_proxy.proxy_from_env?
raise "Expected proxy_address to be nil" unless http_no_proxy.proxy_address.nil?
# ---------------------------------------------------------------------------
# 5. IPv6 literal URI parsing in net_http_connection
# ---------------------------------------------------------------------------
env_ipv6 = Faraday::Env.new(:get, nil, URI('http://[::1]:8080/path'), Faraday::RequestOptions.new, {}, nil, nil)
http_ipv6 = adapter.net_http_connection(env_ipv6)
raise "Expected IPv6 address without brackets to be ::1, got #{http_ipv6.address}" unless http_ipv6.address == '::1'
raise "Expected IPv6 port to be 8080" unless http_ipv6.port == 8080
puts "All faraday-net_http contract assertions passed."