http.rb 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1e4577389b2272eb97f9912694fc3e2951c64cf83758c9a6f05b544dab99f3f
4
- data.tar.gz: 13574567a8fabe8ac8693cda1cd183703eb8d7f57f94da20ffe249feb4b1a52b
3
+ metadata.gz: 192aecaee0d22accbabb0b03b00f987cf7902c4958d6d5dab823515f4e681408
4
+ data.tar.gz: 1adb47bbf1b800b6e3fa9f7767db4a5b63f0b23abe12547056e564bda0c76713
5
5
  SHA512:
6
- metadata.gz: f15f20fb2292d31e28da282fd138463234a2cead1e153a963c32a298b3fee441fcd50958203be30a103eb2c176da18f4beccdd6b362624e1c2769c1ee5b351f8
7
- data.tar.gz: c8062c4c3f8ea7ffba22ac31f5e53288b8b36941651df1d087b18ec6e9bff46178e45afd421fc6218a910d61dc32e6cf410182336d058f28136b302589e1869a
6
+ metadata.gz: 608a398a78d14c9ba1a40db7478510b5a25cc073898a9fa1759c783b3aec8b9f6846597662972f15552f561a6f9e8269485053aab2f707e874f0c753a98144df
7
+ data.tar.gz: 8d9e7449e938c01bad80526aa566cc9886c76df5020cbc556dd458e1acb6f0c2af1b23d3b53dc872df39ec6f27f1c828bbe5bcdc9cfea31c4b5cd3167e129c1d
data/CHANGELOG CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## 20260522
4
4
 
5
+ 0.24.0: ok? predicate now means 200 specifically.
6
+
7
+ 1. ~ Net::HTTPResponse::StatusPredicates: ok? is now defined as @code == '200' rather than aliased to successful?. The alias semantics (any 2xx) misled — "OK" is the reason-phrase for 200 specifically, not the 2xx class. Migration: callers wanting any-2xx should use successful? (or its alias success?).
8
+ 2. + test/Net/HTTPResponse/StatusPredicates_test.rb: Specs for ok? against 200, other 2xx codes, and a 4xx code.
9
+ 3. ~ README.md: Status-predicate section rewritten — single coherent reference for the predicate set, with ok? listed as 200-specific.
10
+ 4. ~ HTTP::VERSION: /0.23.0/0.24.0/
11
+ 5. ~ CHANGELOG: + 0.24.0 entry
12
+
13
+ ## 20260522
14
+
5
15
  0.23.0: Fix cross-scheme redirect SSL leak; clamp negative Retry-After.
6
16
 
7
17
  1. ~ HTTP.request: Compute http-object SSL configuration via options.merge instead of mutating the caller's options hash with auto-derived use_ssl and verify_mode. The previous ||= writes meant an HTTPS→HTTP redirect carried use_ssl: true through to the recursive call against the HTTP host, attempting an SSL handshake on the plain-HTTP port. Cross-scheme redirects in both directions now re-derive use_ssl from each URI.
data/README.md CHANGED
@@ -114,48 +114,35 @@ options = {
114
114
 
115
115
  ### Response status predicate methods
116
116
 
117
+ Every response carries predicates for each status class:
118
+
117
119
  ```ruby
118
- # 1xx
119
- response = HTTP.get('http://example.com')
120
- response.informational?
121
- # => true
120
+ response.informational? # 1xx
121
+ response.successful? # 2xx (aliased as success?)
122
+ response.redirection? # 3xx
123
+ response.client_error? # 4xx
124
+ response.server_error? # 5xx
125
+ response.error? # 4xx or 5xx
126
+ response.ok? # 200 specifically
127
+ ```
122
128
 
123
- # 2xx
124
- response = HTTP.get('http://example.com')
125
- response.success?
126
- # => true
129
+ Redirects are followed by default, so a 3xx is only surfaced when `no_redirect` is set:
127
130
 
128
- # 3xx
129
- response = HTTP.get('http://example.com', {}, {}, {no_redirect: true})
131
+ ```ruby
132
+ response = HTTP.get('http://example.com/moved', {}, {}, {no_redirect: true})
130
133
  response.redirection?
131
134
  # => true
132
- response.success?
135
+ response.successful?
133
136
  # => false
137
+ ```
134
138
 
135
- response = HTTP.get('http://example.com', {}, {}, {no_redirect: false})
136
- response.redirection?
137
- # => false
138
- response.success?
139
- # => true
139
+ Without `no_redirect`, the redirect is followed and `response` is the final destination:
140
140
 
141
- response = HTTP.get('http://example.com')
141
+ ```ruby
142
+ response = HTTP.get('http://example.com/moved')
142
143
  response.redirection?
143
144
  # => false
144
- response.success?
145
- # => true
146
-
147
- # 4xx
148
- response = HTTP.get('http://example.com')
149
- response.client_error?
150
- # => true
151
- response.error?
152
- # => true
153
-
154
- # 5xx
155
- response = HTTP.get('http://example.com')
156
- response.server_error?
157
- # => true
158
- response.error?
145
+ response.successful?
159
146
  # => true
160
147
  ```
161
148
 
data/lib/HTTP/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '0.23.0'
5
+ VERSION = '0.24.0'
6
6
  end
@@ -12,7 +12,10 @@ module Net
12
12
  @code =~ /^2/ ? true : false
13
13
  end
14
14
  alias_method :success?, :successful?
15
- alias_method :ok?, :successful?
15
+
16
+ def ok?
17
+ @code == '200'
18
+ end
16
19
 
17
20
  def redirection?
18
21
  @code =~ /^3/ ? true : false
@@ -0,0 +1,28 @@
1
+ # test/Net/HTTPResponse/StatusPredicates_test.rb
2
+
3
+ require_relative '../../helper'
4
+
5
+ describe Net::HTTPResponse::StatusPredicates do
6
+ let(:response_class) do
7
+ Class.new do
8
+ include Net::HTTPResponse::StatusPredicates
9
+ def initialize(code); @code = code; end
10
+ end
11
+ end
12
+
13
+ describe "#ok?" do
14
+ it "returns true for 200" do
15
+ _(response_class.new('200').ok?).must_equal(true)
16
+ end
17
+
18
+ it "returns false for other 2xx codes" do
19
+ ['201', '202', '204'].each do |code|
20
+ _(response_class.new(code).ok?).must_equal(false)
21
+ end
22
+ end
23
+
24
+ it "returns false for non-2xx codes" do
25
+ _(response_class.new('404').ok?).must_equal(false)
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -117,6 +117,7 @@ files:
117
117
  - test/HTTP/post_test.rb
118
118
  - test/HTTP/put_test.rb
119
119
  - test/HTTP/trace_test.rb
120
+ - test/Net/HTTPResponse/StatusPredicates_test.rb
120
121
  - test/helper.rb
121
122
  homepage: http://github.com/thoran/HTTP
122
123
  licenses: