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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee3df6b6afad0f163708cc0fc0f0a16f4a3b394b56c3c389c55a55274f38c3e7
4
- data.tar.gz: 17a0329a4c031e923cd597af5abcd31d08a853ffbb9d9a58308f6bb44b02b88d
3
+ metadata.gz: 76efd58d8b7892a8c7cd99b94ba163b3e7af2c7c213710d09d4f0ff5751fb01c
4
+ data.tar.gz: 69b629454de4153eac43b49c1e622889a69a90b8b574be7a91af0668240c7b72
5
5
  SHA512:
6
- metadata.gz: 27b412cb8ea24d0a24bc5f3a835cef426481ca6f921323629b0bbabf0b9752373c5f6904179984068fd8a1e7c666f29c989636baa43989a835259252a0278eef
7
- data.tar.gz: 52772055904e6f294fb72a13d270b269b37dc3b588c91afe517e3ea74fb639aac6b6586092cb1fa1de65eb9c518290e79ddde3b6804e65b5b532233d295e0d38
6
+ metadata.gz: bf1fe9f92f33a2b2c32ae4ca1c896076ab22df06551b7e669a21c616a2c89d36942a18a3520d3ecb3fd5db387481ac44abbd7c70dc8b39bce4987a681819ce1f
7
+ data.tar.gz: 143b8dc3a5f8788c552e17ac45ee20ed0313e16bccb16de94d9a22d96b69a23e24d264c2978388b2b01e7f43d84834d027c65c901e3ed6d8fd668763eb422375
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
5
- /doc/
6
5
  /pkg/
7
6
  /spec/reports/
8
7
  /tmp/
@@ -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'
@@ -1,33 +1,34 @@
1
1
  # frozen_string_literal: false
2
- # Net::HTTP exception class.
3
- # You cannot use Net::HTTPExceptions directly; instead, you must use
4
- # its subclasses.
5
- module Net::HTTPExceptions
6
- def initialize(msg, res) #:nodoc:
7
- super msg
8
- @response = res
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
- # for compatibility
25
- Net::HTTPClientException = Net::HTTPServerException
15
+ class HTTPError < ProtocolError
16
+ include HTTPExceptions
17
+ end
26
18
 
27
- class Net::HTTPFatalError < Net::ProtoFatalError
28
- include Net::HTTPExceptions
29
- end
19
+ class HTTPRetriableError < ProtoRetriableError
20
+ include HTTPExceptions
21
+ end
30
22
 
31
- module Net
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
- raise ArgumentError, "no host component for URI" unless uri_or_path.hostname
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