net-http 0.1.0 → 0.1.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: 14bdacaf426ba55dbcb6185d8f79591c7197574e40429fce13a9d7d3a8471245
4
- data.tar.gz: f1c49cd5d4ddc6f465a58b6b01e4a1f9ac871386e018b16e34b747a001d84fb3
3
+ metadata.gz: a306a97039eef1800016a611dee36fa0d342b5f234bf6e0a512d981abd12ce8d
4
+ data.tar.gz: 39583accf1ec3b888c4e368eb0d3cf41add46ebfd18a6d7dcbea1cc69712f219
5
5
  SHA512:
6
- metadata.gz: 7ecc73e91fd63c65b108ff6085028f7490c597b346fa03887b34e8693600618d513bd243eccbf0d9a5cfb808418f1bb548c71ff546358ded71e4641c596927a0
7
- data.tar.gz: a89f8b7a499c914d94745d3b74c09206144fe7d8336b64aa1f3bfde9ed7890206c6b957834210960ff2272018881c500e65d05de73347f30534a55adaa9a447e
6
+ metadata.gz: 21ab016c4d12100c405aec7b8426d81f4a88ac2bc7019353d729837d17e3a95899df04818f787319c32f29b349b7527b7903a65a897e8353382d5461070465c7
7
+ data.tar.gz: 38593be710550d52aaf31d50d746e7f5da92fb1c3d4b451968bda3c0af9b033acefc2fd404f6a083025d340d8abebd7d2061fa77343f081b78bd48c19aa82b39
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/Rakefile CHANGED
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/test_*.rb"]
8
8
  end
9
9
 
10
+ task :sync_tool do
11
+ require 'fileutils'
12
+ FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
13
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15
+ end
16
+
10
17
  task :default => :test
@@ -388,6 +388,7 @@ module Net #:nodoc:
388
388
  class HTTP < Protocol
389
389
 
390
390
  # :stopdoc:
391
+ VERSION = "0.1.1"
391
392
  Revision = %q$Revision$.split[1]
392
393
  HTTPVersion = '1.1'
393
394
  begin
@@ -427,7 +428,7 @@ module Net #:nodoc:
427
428
  #
428
429
  # Gets the body text from the target and outputs it to $stdout. The
429
430
  # target can either be specified as
430
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
431
+ # (+uri+, +headers+), or as (+host+, +path+, +port+ = 80); so:
431
432
  #
432
433
  # Net::HTTP.get_print URI('http://www.example.com/index.html')
433
434
  #
@@ -435,8 +436,12 @@ module Net #:nodoc:
435
436
  #
436
437
  # Net::HTTP.get_print 'www.example.com', '/index.html'
437
438
  #
438
- def HTTP.get_print(uri_or_host, path = nil, port = nil)
439
- get_response(uri_or_host, path, port) {|res|
439
+ # you can also specify request headers:
440
+ #
441
+ # Net::HTTP.get_print URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' }
442
+ #
443
+ def HTTP.get_print(uri_or_host, path_or_headers = nil, port = nil)
444
+ get_response(uri_or_host, path_or_headers, port) {|res|
440
445
  res.read_body do |chunk|
441
446
  $stdout.print chunk
442
447
  end
@@ -446,7 +451,7 @@ module Net #:nodoc:
446
451
 
447
452
  # Sends a GET request to the target and returns the HTTP response
448
453
  # as a string. The target can either be specified as
449
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
454
+ # (+uri+, +headers+), or as (+host+, +path+, +port+ = 80); so:
450
455
  #
451
456
  # print Net::HTTP.get(URI('http://www.example.com/index.html'))
452
457
  #
@@ -454,13 +459,17 @@ module Net #:nodoc:
454
459
  #
455
460
  # print Net::HTTP.get('www.example.com', '/index.html')
456
461
  #
457
- def HTTP.get(uri_or_host, path = nil, port = nil)
458
- get_response(uri_or_host, path, port).body
462
+ # you can also specify request headers:
463
+ #
464
+ # Net::HTTP.get(URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' })
465
+ #
466
+ def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
467
+ get_response(uri_or_host, path_or_headers, port).body
459
468
  end
460
469
 
461
470
  # Sends a GET request to the target and returns the HTTP response
462
471
  # as a Net::HTTPResponse object. The target can either be specified as
463
- # (+uri+), or as (+host+, +path+, +port+ = 80); so:
472
+ # (+uri+, +headers+), or as (+host+, +path+, +port+ = 80); so:
464
473
  #
465
474
  # res = Net::HTTP.get_response(URI('http://www.example.com/index.html'))
466
475
  # print res.body
@@ -470,17 +479,23 @@ module Net #:nodoc:
470
479
  # res = Net::HTTP.get_response('www.example.com', '/index.html')
471
480
  # print res.body
472
481
  #
473
- def HTTP.get_response(uri_or_host, path = nil, port = nil, &block)
474
- if path
482
+ # you can also specify request headers:
483
+ #
484
+ # Net::HTTP.get_response(URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' })
485
+ #
486
+ def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
487
+ if path_or_headers && !path_or_headers.is_a?(Hash)
475
488
  host = uri_or_host
489
+ path = path_or_headers
476
490
  new(host, port || HTTP.default_port).start {|http|
477
491
  return http.request_get(path, &block)
478
492
  }
479
493
  else
480
494
  uri = uri_or_host
495
+ headers = path_or_headers
481
496
  start(uri.hostname, uri.port,
482
497
  :use_ssl => uri.scheme == 'https') {|http|
483
- return http.request_get(uri, &block)
498
+ return http.request_get(uri, headers, &block)
484
499
  }
485
500
  end
486
501
  end
@@ -571,7 +586,7 @@ module Net #:nodoc:
571
586
  # _opt_ :: optional hash
572
587
  #
573
588
  # _opt_ sets following values by its accessor.
574
- # The keys are ipaddr, ca_file, ca_path, cert, cert_store, ciphers,
589
+ # The keys are ipaddr, ca_file, ca_path, cert, cert_store, ciphers, keep_alive_timeout,
575
590
  # close_on_empty_response, key, open_timeout, read_timeout, write_timeout, ssl_timeout,
576
591
  # ssl_version, use_ssl, verify_callback, verify_depth and verify_mode.
577
592
  # If you set :use_ssl as true, you can use https and default value of
@@ -836,6 +851,7 @@ module Net #:nodoc:
836
851
  :@cert,
837
852
  :@cert_store,
838
853
  :@ciphers,
854
+ :@extra_chain_cert,
839
855
  :@key,
840
856
  :@ssl_timeout,
841
857
  :@ssl_version,
@@ -852,6 +868,7 @@ module Net #:nodoc:
852
868
  :cert,
853
869
  :cert_store,
854
870
  :ciphers,
871
+ :extra_chain_cert,
855
872
  :key,
856
873
  :ssl_timeout,
857
874
  :ssl_version,
@@ -882,6 +899,10 @@ module Net #:nodoc:
882
899
  # Sets the available ciphers. See OpenSSL::SSL::SSLContext#ciphers=
883
900
  attr_accessor :ciphers
884
901
 
902
+ # Sets the extra X509 certificates to be added to the certificate chain.
903
+ # See OpenSSL::SSL::SSLContext#extra_chain_cert=
904
+ attr_accessor :extra_chain_cert
905
+
885
906
  # Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
886
907
  # (This method is appeared in Michal Rokos's OpenSSL extension.)
887
908
  attr_accessor :key
@@ -423,30 +423,50 @@ module Net::HTTPHeader
423
423
  alias form_data= set_form_data
424
424
 
425
425
  # Set an HTML form data set.
426
- # +params+ is the form data set; it is an Array of Arrays or a Hash
427
- # +enctype is the type to encode the form data set.
428
- # It is application/x-www-form-urlencoded or multipart/form-data.
429
- # +formopt+ is an optional hash to specify the detail.
426
+ # +params+ :: The form data to set, which should be an enumerable.
427
+ # See below for more details.
428
+ # +enctype+ :: The content type to use to encode the form submission,
429
+ # which should be application/x-www-form-urlencoded or
430
+ # multipart/form-data.
431
+ # +formopt+ :: An options hash, supporting the following options:
432
+ # :boundary :: The boundary of the multipart message. If
433
+ # not given, a random boundary will be used.
434
+ # :charset :: The charset of the form submission. All
435
+ # field names and values of non-file fields
436
+ # should be encoded with this charset.
430
437
  #
431
- # boundary:: the boundary of the multipart message
432
- # charset:: the charset of the message. All names and the values of
433
- # non-file fields are encoded as the charset.
434
- #
435
- # Each item of params is an array and contains following items:
436
- # +name+:: the name of the field
437
- # +value+:: the value of the field, it should be a String or a File
438
- # +opt+:: an optional hash to specify additional information
438
+ # Each item of params should respond to +each+ and yield 2-3 arguments,
439
+ # or an array of 2-3 elements. The arguments yielded should be:
440
+ # * The name of the field.
441
+ # * The value of the field, it should be a String or a File or IO-like.
442
+ # * An options hash, supporting the following options, only
443
+ # used for file uploads:
444
+ # :filename :: The name of the file to use.
445
+ # :content_type :: The content type of the uploaded file.
439
446
  #
440
447
  # Each item is a file field or a normal field.
441
- # If +value+ is a File object or the +opt+ have a filename key,
448
+ # If +value+ is a File object or the +opt+ hash has a :filename key,
442
449
  # the item is treated as a file field.
443
450
  #
444
- # If Transfer-Encoding is set as chunked, this send the request in
451
+ # If Transfer-Encoding is set as chunked, this sends the request using
445
452
  # chunked encoding. Because chunked encoding is HTTP/1.1 feature,
446
- # you must confirm the server to support HTTP/1.1 before sending it.
453
+ # you should confirm that the server supports HTTP/1.1 before using
454
+ # chunked encoding.
447
455
  #
448
456
  # Example:
449
- # http.set_form([["q", "ruby"], ["lang", "en"]])
457
+ # req.set_form([["q", "ruby"], ["lang", "en"]])
458
+ #
459
+ # req.set_form({"f"=>File.open('/path/to/filename')},
460
+ # "multipart/form-data",
461
+ # charset: "UTF-8",
462
+ # )
463
+ #
464
+ # req.set_form([["f",
465
+ # File.open('/path/to/filename.bar'),
466
+ # {filename: "other-filename.foo"}
467
+ # ]],
468
+ # "multipart/form-data",
469
+ # )
450
470
  #
451
471
  # See also RFC 2388, RFC 2616, HTML 4.01, and HTML5
452
472
  #
@@ -268,12 +268,13 @@ class Net::HTTPResponse
268
268
 
269
269
  begin
270
270
  yield inflate_body_io
271
+ success = true
271
272
  ensure
272
- orig_err = $!
273
273
  begin
274
274
  inflate_body_io.finish
275
275
  rescue => err
276
- raise orig_err || err
276
+ # Ignore #finish's error if there is an exception from yield
277
+ raise err if success
277
278
  end
278
279
  end
279
280
  when 'none', 'identity' then
@@ -1,12 +1,15 @@
1
- begin
2
- require_relative "lib/net/http/version"
3
- rescue LoadError # Fallback to load version file in ruby core repository
4
- require_relative "version"
1
+ # frozen_string_literal: true
2
+
3
+ name = File.basename(__FILE__, ".gemspec")
4
+ version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
5
+ break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
6
+ /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7
+ end rescue nil
5
8
  end
6
9
 
7
10
  Gem::Specification.new do |spec|
8
- spec.name = "net-http"
9
- spec.version = Net::Http::VERSION
11
+ spec.name = name
12
+ spec.version = version
10
13
  spec.authors = ["NARUSE, Yui"]
11
14
  spec.email = ["naruse@airemix.jp"]
12
15
 
@@ -14,6 +17,7 @@ Gem::Specification.new do |spec|
14
17
  spec.description = %q{HTTP client api for Ruby.}
15
18
  spec.homepage = "https://github.com/ruby/net-http"
16
19
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
17
21
 
18
22
  spec.metadata["homepage_uri"] = spec.homepage
19
23
  spec.metadata["source_code_uri"] = spec.homepage
@@ -21,9 +25,12 @@ Gem::Specification.new do |spec|
21
25
  # Specify which files should be added to the gem when it is released.
22
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
27
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
29
  end
26
30
  spec.bindir = "exe"
27
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
32
  spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency "net-protocol"
35
+ spec.add_dependency "uri"
29
36
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NARUSE, Yui
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-protocol
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: uri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: HTTP client api for Ruby.
14
42
  email:
15
43
  - naruse@airemix.jp
@@ -21,6 +49,7 @@ files:
21
49
  - ".gitignore"
22
50
  - Gemfile
23
51
  - Gemfile.lock
52
+ - LICENSE.txt
24
53
  - README.md
25
54
  - Rakefile
26
55
  - bin/console
@@ -36,15 +65,16 @@ files:
36
65
  - lib/net/http/response.rb
37
66
  - lib/net/http/responses.rb
38
67
  - lib/net/http/status.rb
39
- - lib/net/http/version.rb
40
68
  - lib/net/https.rb
41
69
  - net-http.gemspec
42
70
  homepage: https://github.com/ruby/net-http
43
- licenses: []
71
+ licenses:
72
+ - Ruby
73
+ - BSD-2-Clause
44
74
  metadata:
45
75
  homepage_uri: https://github.com/ruby/net-http
46
76
  source_code_uri: https://github.com/ruby/net-http
47
- post_install_message:
77
+ post_install_message:
48
78
  rdoc_options: []
49
79
  require_paths:
50
80
  - lib
@@ -59,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
89
  - !ruby/object:Gem::Version
60
90
  version: '0'
61
91
  requirements: []
62
- rubygems_version: 3.2.0.pre1
63
- signing_key:
92
+ rubygems_version: 3.2.2
93
+ signing_key:
64
94
  specification_version: 4
65
95
  summary: HTTP client api for Ruby.
66
96
  test_files: []
@@ -1,5 +0,0 @@
1
- module Net
2
- module Http
3
- VERSION = "0.1.0"
4
- end
5
- end