net-http 0.1.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +3 -5
- data/.gitignore +0 -1
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/doc/net-http/examples.rdoc +30 -0
- data/lib/net/http/backward.rb +26 -12
- data/lib/net/http/exceptions.rb +27 -26
- data/lib/net/http/generic_request.rb +6 -7
- data/lib/net/http/header.rb +473 -105
- data/lib/net/http/request.rb +27 -5
- data/lib/net/http/requests.rb +296 -24
- data/lib/net/http/response.rb +303 -12
- data/lib/net/http/responses.rb +638 -223
- data/lib/net/http.rb +681 -371
- data/net-http.gemspec +0 -2
- metadata +5 -18
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2201663415fa5809c53f6c1d8a06524739bcee246443e22175aa89cda45c92c
|
4
|
+
data.tar.gz: 971f571f8d9966a09baf43a5117d9f072ae78b890e6cc4991a958081728671c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '086e4def849a69d4ecad94e1a13fe35eee82453f8748be247ea2c133b40ae7d3b419a0f71fa9dcd7efe783d0b725a13d527e287da1ccc406f7daa5700f2ec8e5'
|
7
|
+
data.tar.gz: 47a0f2d46fe8a9bc328241fb0fc90ea1c4285b0e46460998e40650a930bd96743051911e62b790d4502b39a007a5a04e260affe42d584bb73442ab414b51f1e3
|
data/.github/workflows/test.yml
CHANGED
@@ -7,18 +7,16 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ 2.7, 2.6, head ]
|
10
|
+
ruby: [ 3.1, '3.0', 2.7, 2.6, head ]
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
12
12
|
runs-on: ${{ matrix.os }}
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v3
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
19
19
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
20
|
+
run: bundle install
|
23
21
|
- name: Run test
|
24
22
|
run: rake test
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
task :sync_tool do
|
11
11
|
require 'fileutils'
|
12
|
-
FileUtils.cp "../ruby/tool/lib/
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
13
|
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
14
|
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
15
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Examples here assume that <tt>net/http</tt> has been required
|
2
|
+
(which also requires +uri+):
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
Many code examples here use these example websites:
|
7
|
+
|
8
|
+
- https://jsonplaceholder.typicode.com.
|
9
|
+
- http://example.com.
|
10
|
+
|
11
|
+
Some examples also assume these variables:
|
12
|
+
|
13
|
+
uri = URI('https://jsonplaceholder.typicode.com')
|
14
|
+
uri.freeze # Examples may not modify.
|
15
|
+
hostname = uri.hostname # => "jsonplaceholder.typicode.com"
|
16
|
+
port = uri.port # => 443
|
17
|
+
|
18
|
+
So that example requests may be written as:
|
19
|
+
|
20
|
+
Net::HTTP.get(uri)
|
21
|
+
Net::HTTP.get(hostname, '/index.html')
|
22
|
+
Net::HTTP.start(hostname) do |http|
|
23
|
+
http.get('/todos/1')
|
24
|
+
http.get('/todos/2')
|
25
|
+
end
|
26
|
+
|
27
|
+
An example that needs a modified URI first duplicates +uri+, then modifies the duplicate:
|
28
|
+
|
29
|
+
_uri = uri.dup
|
30
|
+
_uri.path = '/todos/1'
|
data/lib/net/http/backward.rb
CHANGED
@@ -5,22 +5,36 @@
|
|
5
5
|
|
6
6
|
class Net::HTTP
|
7
7
|
ProxyMod = ProxyDelta
|
8
|
-
|
9
|
-
|
10
|
-
module Net
|
11
|
-
HTTPSession = Net::HTTP
|
8
|
+
deprecate_constant :ProxyMod
|
12
9
|
end
|
13
10
|
|
14
11
|
module Net::NetPrivate
|
15
12
|
HTTPRequest = ::Net::HTTPRequest
|
13
|
+
deprecate_constant :HTTPRequest
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
Net::HTTPRedirectionCode = Net::HTTPRedirection
|
21
|
-
Net::HTTPRetriableCode = Net::HTTPRedirection
|
22
|
-
Net::HTTPClientErrorCode = Net::HTTPClientError
|
23
|
-
Net::HTTPFatalErrorCode = Net::HTTPClientError
|
24
|
-
Net::HTTPServerErrorCode = Net::HTTPServerError
|
25
|
-
Net::HTTPResponceReceiver = Net::HTTPResponse
|
16
|
+
module Net
|
17
|
+
HTTPSession = HTTP
|
26
18
|
|
19
|
+
HTTPInformationCode = HTTPInformation
|
20
|
+
HTTPSuccessCode = HTTPSuccess
|
21
|
+
HTTPRedirectionCode = HTTPRedirection
|
22
|
+
HTTPRetriableCode = HTTPRedirection
|
23
|
+
HTTPClientErrorCode = HTTPClientError
|
24
|
+
HTTPFatalErrorCode = HTTPClientError
|
25
|
+
HTTPServerErrorCode = HTTPServerError
|
26
|
+
HTTPResponseReceiver = HTTPResponse
|
27
|
+
|
28
|
+
HTTPResponceReceiver = HTTPResponse # Typo since 2001
|
29
|
+
|
30
|
+
deprecate_constant :HTTPSession,
|
31
|
+
:HTTPInformationCode,
|
32
|
+
:HTTPSuccessCode,
|
33
|
+
:HTTPRedirectionCode,
|
34
|
+
:HTTPRetriableCode,
|
35
|
+
:HTTPClientErrorCode,
|
36
|
+
:HTTPFatalErrorCode,
|
37
|
+
:HTTPServerErrorCode,
|
38
|
+
:HTTPResponseReceiver,
|
39
|
+
:HTTPResponceReceiver
|
40
|
+
end
|
data/lib/net/http/exceptions.rb
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
module Net
|
3
|
+
# Net::HTTP exception class.
|
4
|
+
# You cannot use Net::HTTPExceptions directly; instead, you must use
|
5
|
+
# its subclasses.
|
6
|
+
module HTTPExceptions
|
7
|
+
def initialize(msg, res) #:nodoc:
|
8
|
+
super msg
|
9
|
+
@response = res
|
10
|
+
end
|
11
|
+
attr_reader :response
|
12
|
+
alias data response #:nodoc: obsolete
|
9
13
|
end
|
10
|
-
attr_reader :response
|
11
|
-
alias data response #:nodoc: obsolete
|
12
|
-
end
|
13
|
-
class Net::HTTPError < Net::ProtocolError
|
14
|
-
include Net::HTTPExceptions
|
15
|
-
end
|
16
|
-
class Net::HTTPRetriableError < Net::ProtoRetriableError
|
17
|
-
include Net::HTTPExceptions
|
18
|
-
end
|
19
|
-
class Net::HTTPServerException < Net::ProtoServerError
|
20
|
-
# We cannot use the name "HTTPServerError", it is the name of the response.
|
21
|
-
include Net::HTTPExceptions
|
22
|
-
end
|
23
14
|
|
24
|
-
|
25
|
-
|
15
|
+
class HTTPError < ProtocolError
|
16
|
+
include HTTPExceptions
|
17
|
+
end
|
26
18
|
|
27
|
-
class
|
28
|
-
|
29
|
-
end
|
19
|
+
class HTTPRetriableError < ProtoRetriableError
|
20
|
+
include HTTPExceptions
|
21
|
+
end
|
30
22
|
|
31
|
-
|
23
|
+
class HTTPClientException < ProtoServerError
|
24
|
+
include HTTPExceptions
|
25
|
+
end
|
26
|
+
|
27
|
+
class HTTPFatalError < ProtoFatalError
|
28
|
+
include HTTPExceptions
|
29
|
+
end
|
30
|
+
|
31
|
+
# We cannot use the name "HTTPServerError", it is the name of the response.
|
32
|
+
HTTPServerException = HTTPClientException # :nodoc:
|
32
33
|
deprecate_constant(:HTTPServerException)
|
33
34
|
end
|
@@ -15,7 +15,8 @@ class Net::HTTPGenericRequest
|
|
15
15
|
|
16
16
|
if URI === uri_or_path then
|
17
17
|
raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
|
18
|
-
|
18
|
+
hostname = uri_or_path.hostname
|
19
|
+
raise ArgumentError, "no host component for URI" unless (hostname && hostname.length > 0)
|
19
20
|
@uri = uri_or_path.dup
|
20
21
|
host = @uri.hostname.dup
|
21
22
|
host << ":".freeze << @uri.port.to_s if @uri.port != @uri.default_port
|
@@ -31,12 +32,12 @@ class Net::HTTPGenericRequest
|
|
31
32
|
|
32
33
|
@decode_content = false
|
33
34
|
|
34
|
-
if
|
35
|
+
if Net::HTTP::HAVE_ZLIB then
|
35
36
|
if !initheader ||
|
36
37
|
!initheader.keys.any? { |k|
|
37
38
|
%w[accept-encoding range].include? k.downcase
|
38
39
|
} then
|
39
|
-
@decode_content = true
|
40
|
+
@decode_content = true if @response_has_body
|
40
41
|
initheader = initheader ? initheader.dup : {}
|
41
42
|
initheader["accept-encoding"] =
|
42
43
|
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
@@ -143,7 +144,7 @@ class Net::HTTPGenericRequest
|
|
143
144
|
end
|
144
145
|
|
145
146
|
if host = self['host']
|
146
|
-
host.sub!(/:.*/
|
147
|
+
host.sub!(/:.*/m, ''.freeze)
|
147
148
|
elsif host = @uri.host
|
148
149
|
else
|
149
150
|
host = addr
|
@@ -202,9 +203,7 @@ class Net::HTTPGenericRequest
|
|
202
203
|
IO.copy_stream(f, chunker)
|
203
204
|
chunker.finish
|
204
205
|
else
|
205
|
-
|
206
|
-
# If sock.io is an SSLSocket, copy_stream will hit SSL_write()
|
207
|
-
IO.copy_stream(f, sock.io)
|
206
|
+
IO.copy_stream(f, sock)
|
208
207
|
end
|
209
208
|
end
|
210
209
|
|