http.rb 0.23.0 → 0.25.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 +4 -4
- data/CHANGELOG +24 -0
- data/README.md +19 -32
- data/http.rb.gemspec +1 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/verbs.rb +2 -3
- data/lib/HTTP.rb +0 -3
- data/lib/Net/HTTPResponse/StatusPredicates.rb +4 -1
- data/test/Net/HTTPResponse/StatusPredicates_test.rb +28 -0
- metadata +3 -6
- data/lib/String/to_const.rb +0 -7
- data/lib/Thoran/Array/AllButFirst/all_but_first.rb +0 -28
- data/lib/Thoran/Array/FirstX/firstX.rb +0 -32
- data/lib/Thoran/String/ToConst/to_const.rb +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e13135b5b435a5698be8796e1b9875519747ec50ef9b67c28b81e2f635f43934
|
|
4
|
+
data.tar.gz: 05adbd72d459b796093914c3e47b1be023fd543a41305b4fa42b8d90e3fc3a6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db5b30d4185591e0a52fb740514f135b4bd21e06482f160d1ecf7c6c69068e57d8b27e2af9735d8beabd8e41a33ad4f25e400d9ed9999225b576b3ef79e4d545
|
|
7
|
+
data.tar.gz: a751c3f915491a27cbea213524c5c83271b3b61b1c7b04c9c279e8f26956b718d45467a970a0eb22eb5d5d7bc710cbb6074105dbb55cdd61c7f257424a621dd2
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## 20260522
|
|
4
4
|
|
|
5
|
+
0.25.0: Remove unused internal machinery; require Ruby >= 3.2.
|
|
6
|
+
|
|
7
|
+
1. ~ HTTP/verbs.rb: /"Net::HTTP::#{verb.to_s.capitalize}".to_const/Net::HTTP.const_get(verb.to_s.capitalize)/. The recursive String#to_const was overkill for a single-level lookup inside Net::HTTP; const_get does it directly.
|
|
8
|
+
2. - lib/String/to_const.rb
|
|
9
|
+
3. - lib/Thoran/String/ToConst/to_const.rb
|
|
10
|
+
4. - lib/Thoran/Array/AllButFirst/all_but_first.rb (was only used by to_const)
|
|
11
|
+
5. - lib/Thoran/Array/FirstX/firstX.rb (was only used by all_but_first)
|
|
12
|
+
6. ~ lib/HTTP.rb: Remove $LOAD_PATH.unshift; rubygems puts lib/ on the load path for installed gems and bundler does the same for local development.
|
|
13
|
+
7. ~ http.rb.gemspec: /required_ruby_version = '>= 2.7'/required_ruby_version = '>= 3.2'/. Aligns with the minitest 6.0 floor used in development; the runtime would still load on 2.7, but claiming compatibility with a Ruby the test suite can't be run against is a fiction worth ending before 1.0.
|
|
14
|
+
8. ~ HTTP::VERSION: /0.24.0/0.25.0/
|
|
15
|
+
9. ~ CHANGELOG: + 0.25.0 entry
|
|
16
|
+
|
|
17
|
+
## 20260522
|
|
18
|
+
|
|
19
|
+
0.24.0: ok? predicate now means 200 specifically.
|
|
20
|
+
|
|
21
|
+
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?).
|
|
22
|
+
2. + test/Net/HTTPResponse/StatusPredicates_test.rb: Specs for ok? against 200, other 2xx codes, and a 4xx code.
|
|
23
|
+
3. ~ README.md: Status-predicate section rewritten — single coherent reference for the predicate set, with ok? listed as 200-specific.
|
|
24
|
+
4. ~ HTTP::VERSION: /0.23.0/0.24.0/
|
|
25
|
+
5. ~ CHANGELOG: + 0.24.0 entry
|
|
26
|
+
|
|
27
|
+
## 20260522
|
|
28
|
+
|
|
5
29
|
0.23.0: Fix cross-scheme redirect SSL leak; clamp negative Retry-After.
|
|
6
30
|
|
|
7
31
|
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
|
|
120
|
-
response.
|
|
121
|
-
#
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
135
|
+
response.successful?
|
|
133
136
|
# => false
|
|
137
|
+
```
|
|
134
138
|
|
|
135
|
-
response
|
|
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
|
-
|
|
141
|
+
```ruby
|
|
142
|
+
response = HTTP.get('http://example.com/moved')
|
|
142
143
|
response.redirection?
|
|
143
144
|
# => false
|
|
144
|
-
response.
|
|
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/http.rb.gemspec
CHANGED
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/verbs.rb
CHANGED
|
@@ -6,7 +6,6 @@ require 'net/http'
|
|
|
6
6
|
|
|
7
7
|
require_relative '../Hash/x_www_form_urlencode'
|
|
8
8
|
require_relative './request'
|
|
9
|
-
require_relative '../String/to_const'
|
|
10
9
|
|
|
11
10
|
module HTTP
|
|
12
11
|
module VERBS
|
|
@@ -21,7 +20,7 @@ module HTTP
|
|
|
21
20
|
unless args.empty?
|
|
22
21
|
request_uri += '?' + args.x_www_form_urlencode
|
|
23
22
|
end
|
|
24
|
-
request_object =
|
|
23
|
+
request_object = Net::HTTP.const_get(verb.to_s.capitalize).new(request_uri)
|
|
25
24
|
request(uri, request_object, headers, options, &block)
|
|
26
25
|
end
|
|
27
26
|
|
|
@@ -31,7 +30,7 @@ module HTTP
|
|
|
31
30
|
VERBS::WITH_BODY.each do |verb|
|
|
32
31
|
define_method(verb) do |uri, data = {}, headers = {}, options = {}, &block|
|
|
33
32
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
34
|
-
request_object =
|
|
33
|
+
request_object = Net::HTTP.const_get(verb.to_s.capitalize).new(uri.request_uri)
|
|
35
34
|
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
|
36
35
|
if data.is_a?(String)
|
|
37
36
|
request_object.body = data
|
data/lib/HTTP.rb
CHANGED
|
@@ -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.
|
|
4
|
+
version: 0.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -102,11 +102,7 @@ files:
|
|
|
102
102
|
- lib/Net/HTTP/set_options.rb
|
|
103
103
|
- lib/Net/HTTPRequest/set_headers.rb
|
|
104
104
|
- lib/Net/HTTPResponse/StatusPredicates.rb
|
|
105
|
-
- lib/String/to_const.rb
|
|
106
105
|
- lib/String/url_encode.rb
|
|
107
|
-
- lib/Thoran/Array/AllButFirst/all_but_first.rb
|
|
108
|
-
- lib/Thoran/Array/FirstX/firstX.rb
|
|
109
|
-
- lib/Thoran/String/ToConst/to_const.rb
|
|
110
106
|
- lib/URI/Generic/use_sslQ.rb
|
|
111
107
|
- test/HTTP/RETRY_test.rb
|
|
112
108
|
- test/HTTP/delete_test.rb
|
|
@@ -117,6 +113,7 @@ files:
|
|
|
117
113
|
- test/HTTP/post_test.rb
|
|
118
114
|
- test/HTTP/put_test.rb
|
|
119
115
|
- test/HTTP/trace_test.rb
|
|
116
|
+
- test/Net/HTTPResponse/StatusPredicates_test.rb
|
|
120
117
|
- test/helper.rb
|
|
121
118
|
homepage: http://github.com/thoran/HTTP
|
|
122
119
|
licenses:
|
|
@@ -129,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
129
126
|
requirements:
|
|
130
127
|
- - ">="
|
|
131
128
|
- !ruby/object:Gem::Version
|
|
132
|
-
version: '2
|
|
129
|
+
version: '3.2'
|
|
133
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
131
|
requirements:
|
|
135
132
|
- - ">="
|
data/lib/String/to_const.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Thoran/Array/AllButFirst/all_but_first.rb
|
|
2
|
-
# Thoran::Array::AllButFirst#all_but_first
|
|
3
|
-
|
|
4
|
-
# 20141223
|
|
5
|
-
# 0.1.0
|
|
6
|
-
|
|
7
|
-
# Description: This returns a copy of the receiving array with the first element removed.
|
|
8
|
-
|
|
9
|
-
# Changes:
|
|
10
|
-
# 1. + Thoran namespace.
|
|
11
|
-
|
|
12
|
-
require 'Thoran/Array/FirstX/firstX'
|
|
13
|
-
|
|
14
|
-
module Thoran
|
|
15
|
-
module Array
|
|
16
|
-
module AllButFirst
|
|
17
|
-
|
|
18
|
-
def all_but_first
|
|
19
|
-
d = self.dup
|
|
20
|
-
d.first!
|
|
21
|
-
d
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
Array.send(:include, Thoran::Array::AllButFirst)
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Thoran/Array/FirstX/firstX.rb
|
|
2
|
-
# Thoran::Array::FirstX#first!
|
|
3
|
-
|
|
4
|
-
# 20180804
|
|
5
|
-
# 0.3.3
|
|
6
|
-
|
|
7
|
-
# Description: Sometimes it makes more sense to treat arrays this way.
|
|
8
|
-
|
|
9
|
-
# Changes since 0.2:
|
|
10
|
-
# 1. Added the original version 0.1.0 of the implementation to the later 0.1.0!
|
|
11
|
-
# 0/1
|
|
12
|
-
# 2. Switched the tests to spec-style.
|
|
13
|
-
# 1/2
|
|
14
|
-
# 3. Added a test for the state of the array afterward, since this is meant to be an in place change.
|
|
15
|
-
# 2/3
|
|
16
|
-
# 4. Added tests for the extended functionality introduced in the first version 0.1.0.
|
|
17
|
-
|
|
18
|
-
module Thoran
|
|
19
|
-
module Array
|
|
20
|
-
module FirstX
|
|
21
|
-
|
|
22
|
-
def first!(n = 1)
|
|
23
|
-
return_value = []
|
|
24
|
-
n.times{return_value << self.shift}
|
|
25
|
-
return_value.size == 1 ? return_value[0] : return_value
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
Array.send(:include, Thoran::Array::FirstX)
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Thoran/String/ToConst/to_const.rb
|
|
2
|
-
# Thoran::String::ToConst#to_const
|
|
3
|
-
|
|
4
|
-
# 20141223
|
|
5
|
-
# 0.2.0
|
|
6
|
-
|
|
7
|
-
# Description: This takes a string and returns a constant, with unlimited namespacing.
|
|
8
|
-
|
|
9
|
-
# History: Derived from Object#to_const 0.3.0, and superceding Object#to_const.
|
|
10
|
-
|
|
11
|
-
# Changes:
|
|
12
|
-
# 1. + Thoran namespace.
|
|
13
|
-
|
|
14
|
-
# Todo:
|
|
15
|
-
# 1. This only works for two levels of constants. Three and you're stuffed. So, this needs to be recursive...
|
|
16
|
-
# Done iteratively as of 0.1.0.
|
|
17
|
-
# 2. Make this work for symbols. However, this will only work if there's no namespacing. ie. :A is OK, but :A::B is not.
|
|
18
|
-
|
|
19
|
-
# Discussion:
|
|
20
|
-
# 1. Should this go separately into classes for which ::const_get will work and be removed from Object? Done as of 0.1.0.
|
|
21
|
-
|
|
22
|
-
require 'Thoran/Array/AllButFirst/all_but_first'
|
|
23
|
-
|
|
24
|
-
module Thoran
|
|
25
|
-
module String
|
|
26
|
-
module ToConst
|
|
27
|
-
|
|
28
|
-
def to_const
|
|
29
|
-
if self =~ /::/
|
|
30
|
-
constants = self.split('::')
|
|
31
|
-
constant = Object.const_get(constants.first)
|
|
32
|
-
constants = constants.all_but_first
|
|
33
|
-
until constants.empty? do
|
|
34
|
-
constant = constant.const_get(constants.shift)
|
|
35
|
-
end
|
|
36
|
-
else
|
|
37
|
-
constant = Object.const_get(self)
|
|
38
|
-
end
|
|
39
|
-
constant
|
|
40
|
-
end
|
|
41
|
-
alias_method :to_constant, :to_const
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
String.send(:include, Thoran::String::ToConst)
|