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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a306a97039eef1800016a611dee36fa0d342b5f234bf6e0a512d981abd12ce8d
4
- data.tar.gz: 39583accf1ec3b888c4e368eb0d3cf41add46ebfd18a6d7dcbea1cc69712f219
3
+ metadata.gz: d2201663415fa5809c53f6c1d8a06524739bcee246443e22175aa89cda45c92c
4
+ data.tar.gz: 971f571f8d9966a09baf43a5117d9f072ae78b890e6cc4991a958081728671c8
5
5
  SHA512:
6
- metadata.gz: 21ab016c4d12100c405aec7b8426d81f4a88ac2bc7019353d729837d17e3a95899df04818f787319c32f29b349b7527b7903a65a897e8353382d5461070465c7
7
- data.tar.gz: 38593be710550d52aaf31d50d746e7f5da92fb1c3d4b451968bda3c0af9b033acefc2fd404f6a083025d340d8abebd7d2061fa77343f081b78bd48c19aa82b39
6
+ metadata.gz: '086e4def849a69d4ecad94e1a13fe35eee82453f8748be247ea2c133b40ae7d3b419a0f71fa9dcd7efe783d0b725a13d527e287da1ccc406f7daa5700f2ec8e5'
7
+ data.tar.gz: 47a0f2d46fe8a9bc328241fb0fc90ea1c4285b0e46460998e40650a930bd96743051911e62b790d4502b39a007a5a04e260affe42d584bb73442ab414b51f1e3
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -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@master
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
@@ -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/
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gemspec
4
4
 
5
5
  gem "rake"
6
6
  gem "test-unit"
7
+ gem "webrick"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Net::Http
1
+ # Net::HTTP
2
2
 
3
3
  Net::HTTP provides a rich library which can be used to build HTTP
4
4
  user-agents. For more details about HTTP see
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/test/unit/core_assertions.rb", "./test/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'
@@ -5,22 +5,36 @@
5
5
 
6
6
  class Net::HTTP
7
7
  ProxyMod = ProxyDelta
8
- end
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
- Net::HTTPInformationCode = Net::HTTPInformation
19
- Net::HTTPSuccessCode = Net::HTTPSuccess
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
@@ -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
@@ -31,12 +32,12 @@ class Net::HTTPGenericRequest
31
32
 
32
33
  @decode_content = false
33
34
 
34
- if @response_has_body and Net::HTTP::HAVE_ZLIB then
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!(/:.*/s, ''.freeze)
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
- # copy_stream can sendfile() to sock.io unless we use SSL.
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