net-http 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/doc/net-http/examples.rdoc +30 -0
- data/lib/net/http/exceptions.rb +27 -26
- data/lib/net/http/generic_request.rb +2 -1
- data/lib/net/http/header.rb +384 -75
- data/lib/net/http/request.rb +27 -5
- data/lib/net/http/requests.rb +296 -24
- data/lib/net/http/response.rb +127 -11
- data/lib/net/http/responses.rb +228 -223
- data/lib/net/http.rb +321 -311
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76efd58d8b7892a8c7cd99b94ba163b3e7af2c7c213710d09d4f0ff5751fb01c
|
4
|
+
data.tar.gz: 69b629454de4153eac43b49c1e622889a69a90b8b574be7a91af0668240c7b72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf1fe9f92f33a2b2c32ae4ca1c896076ab22df06551b7e669a21c616a2c89d36942a18a3520d3ecb3fd5db387481ac44abbd7c70dc8b39bce4987a681819ce1f
|
7
|
+
data.tar.gz: 143b8dc3a5f8788c552e17ac45ee20ed0313e16bccb16de94d9a22d96b69a23e24d264c2978388b2b01e7f43d84834d027c65c901e3ed6d8fd668763eb422375
|
data/.gitignore
CHANGED
@@ -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/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
|