net-http 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/net/http/generic_request.rb +10 -1
- data/lib/net/http/header.rb +56 -15
- data/lib/net/http/request.rb +1 -0
- data/lib/net/http/requests.rb +59 -24
- data/lib/net/http/response.rb +40 -15
- data/lib/net/http.rb +77 -16
- data/sig/manifest.yaml +3 -0
- data/sig/net-http.rbs +5635 -0
- metadata +70 -48
data/lib/net/http.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Net #:nodoc:
|
|
|
37
37
|
# For information about \HTTP, see:
|
|
38
38
|
#
|
|
39
39
|
# - {Hypertext Transfer Protocol}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol].
|
|
40
|
-
# - {
|
|
40
|
+
# - {Technology}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Technology].
|
|
41
41
|
#
|
|
42
42
|
# == About the Examples
|
|
43
43
|
#
|
|
@@ -72,7 +72,7 @@ module Net #:nodoc:
|
|
|
72
72
|
#
|
|
73
73
|
# - If performance is important, consider using sessions, which lower request overhead.
|
|
74
74
|
# This {session}[rdoc-ref:Net::HTTP@Sessions] has multiple requests for
|
|
75
|
-
# {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#
|
|
75
|
+
# {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Method]
|
|
76
76
|
# and {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
|
|
77
77
|
#
|
|
78
78
|
# Net::HTTP.start(hostname) do |http|
|
|
@@ -82,6 +82,7 @@ module Net #:nodoc:
|
|
|
82
82
|
# body = 'Some text'
|
|
83
83
|
# http.post(path, body) # Can also have a block.
|
|
84
84
|
# http.put(path, body)
|
|
85
|
+
# http.query(path, body) # Can also have a block.
|
|
85
86
|
# http.delete(path)
|
|
86
87
|
# http.options(path)
|
|
87
88
|
# http.trace(path)
|
|
@@ -198,7 +199,7 @@ module Net #:nodoc:
|
|
|
198
199
|
# In the block, you can use these instance methods,
|
|
199
200
|
# each of which that sends a single request:
|
|
200
201
|
#
|
|
201
|
-
# - {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#
|
|
202
|
+
# - {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Method]:
|
|
202
203
|
#
|
|
203
204
|
# - #get, #request_get: GET.
|
|
204
205
|
# - #head, #request_head: HEAD.
|
|
@@ -207,6 +208,7 @@ module Net #:nodoc:
|
|
|
207
208
|
# - #options: OPTIONS.
|
|
208
209
|
# - #trace: TRACE.
|
|
209
210
|
# - #patch: PATCH.
|
|
211
|
+
# - #query, #request_query: QUERY.
|
|
210
212
|
#
|
|
211
213
|
# - {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
|
|
212
214
|
#
|
|
@@ -447,7 +449,7 @@ module Net #:nodoc:
|
|
|
447
449
|
# if the response has header <tt>'Content-Range'</tt>.
|
|
448
450
|
#
|
|
449
451
|
# Otherwise decompression (or not) depends on the value of header
|
|
450
|
-
# {Content-Encoding}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#
|
|
452
|
+
# {Content-Encoding}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Content-Encoding_2]:
|
|
451
453
|
#
|
|
452
454
|
# - <tt>'deflate'</tt>, <tt>'gzip'</tt>, or <tt>'x-gzip'</tt>:
|
|
453
455
|
# decompresses the body and deletes the header.
|
|
@@ -460,7 +462,7 @@ module Net #:nodoc:
|
|
|
460
462
|
#
|
|
461
463
|
# First, what's elsewhere. Class Net::HTTP:
|
|
462
464
|
#
|
|
463
|
-
# - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-
|
|
465
|
+
# - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-object-whats-here].
|
|
464
466
|
#
|
|
465
467
|
# This is a categorized summary of methods and attributes.
|
|
466
468
|
#
|
|
@@ -553,6 +555,8 @@ module Net #:nodoc:
|
|
|
553
555
|
# Sends a PROPPATCH request and returns a response object.
|
|
554
556
|
# - {#put}[rdoc-ref:Net::HTTP#put]:
|
|
555
557
|
# Sends a PUT request and returns a response object.
|
|
558
|
+
# - {#query}[rdoc-ref:Net::HTTP#query]:
|
|
559
|
+
# Sends a QUERY request and returns a response object.
|
|
556
560
|
# - {#request}[rdoc-ref:Net::HTTP#request]:
|
|
557
561
|
# Sends a request and returns a response object.
|
|
558
562
|
# - {#request_get}[rdoc-ref:Net::HTTP#request_get]:
|
|
@@ -724,7 +728,7 @@ module Net #:nodoc:
|
|
|
724
728
|
class HTTP < Protocol
|
|
725
729
|
|
|
726
730
|
# :stopdoc:
|
|
727
|
-
VERSION = "0.
|
|
731
|
+
VERSION = "0.10.0"
|
|
728
732
|
HTTPVersion = '1.1'
|
|
729
733
|
begin
|
|
730
734
|
require 'zlib'
|
|
@@ -1304,7 +1308,7 @@ module Net #:nodoc:
|
|
|
1304
1308
|
|
|
1305
1309
|
# Sets whether to determine the proxy from environment variable
|
|
1306
1310
|
# '<tt>ENV['http_proxy']</tt>';
|
|
1307
|
-
# see {Proxy Using ENV
|
|
1311
|
+
# see {Proxy Using ENV}[rdoc-ref:Net::HTTP@Proxy+Using+ENVHTTPProxy].
|
|
1308
1312
|
attr_writer :proxy_from_env
|
|
1309
1313
|
|
|
1310
1314
|
# Sets the proxy address;
|
|
@@ -1531,7 +1535,7 @@ module Net #:nodoc:
|
|
|
1531
1535
|
:verify_depth,
|
|
1532
1536
|
:verify_mode,
|
|
1533
1537
|
:verify_hostname,
|
|
1534
|
-
] # :nodoc:
|
|
1538
|
+
].freeze # :nodoc:
|
|
1535
1539
|
|
|
1536
1540
|
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
|
|
1537
1541
|
|
|
@@ -1550,11 +1554,11 @@ module Net #:nodoc:
|
|
|
1550
1554
|
attr_accessor :cert_store
|
|
1551
1555
|
|
|
1552
1556
|
# Sets or returns the available SSL ciphers.
|
|
1553
|
-
# See {OpenSSL::SSL::SSLContext#ciphers=}[OpenSSL
|
|
1557
|
+
# See {OpenSSL::SSL::SSLContext#ciphers=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ciphers-3D].
|
|
1554
1558
|
attr_accessor :ciphers
|
|
1555
1559
|
|
|
1556
1560
|
# Sets or returns the extra X509 certificates to be added to the certificate chain.
|
|
1557
|
-
# See {OpenSSL::SSL::SSLContext#add_certificate}[OpenSSL
|
|
1561
|
+
# See {OpenSSL::SSL::SSLContext#add_certificate}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-add_certificate].
|
|
1558
1562
|
attr_accessor :extra_chain_cert
|
|
1559
1563
|
|
|
1560
1564
|
# Sets or returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
|
|
@@ -1564,15 +1568,15 @@ module Net #:nodoc:
|
|
|
1564
1568
|
attr_accessor :ssl_timeout
|
|
1565
1569
|
|
|
1566
1570
|
# Sets or returns the SSL version.
|
|
1567
|
-
# See {OpenSSL::SSL::SSLContext#ssl_version=}[OpenSSL
|
|
1571
|
+
# See {OpenSSL::SSL::SSLContext#ssl_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D].
|
|
1568
1572
|
attr_accessor :ssl_version
|
|
1569
1573
|
|
|
1570
1574
|
# Sets or returns the minimum SSL version.
|
|
1571
|
-
# See {OpenSSL::SSL::SSLContext#min_version=}[OpenSSL
|
|
1575
|
+
# See {OpenSSL::SSL::SSLContext#min_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D].
|
|
1572
1576
|
attr_accessor :min_version
|
|
1573
1577
|
|
|
1574
1578
|
# Sets or returns the maximum SSL version.
|
|
1575
|
-
# See {OpenSSL::SSL::SSLContext#max_version=}[OpenSSL
|
|
1579
|
+
# See {OpenSSL::SSL::SSLContext#max_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D].
|
|
1576
1580
|
attr_accessor :max_version
|
|
1577
1581
|
|
|
1578
1582
|
# Sets or returns the callback for the server certification verification.
|
|
@@ -1588,7 +1592,7 @@ module Net #:nodoc:
|
|
|
1588
1592
|
|
|
1589
1593
|
# Sets or returns whether to verify that the server certificate is valid
|
|
1590
1594
|
# for the hostname.
|
|
1591
|
-
# See {OpenSSL::SSL::SSLContext#verify_hostname=}[OpenSSL
|
|
1595
|
+
# See {OpenSSL::SSL::SSLContext#verify_hostname=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#attribute-i-verify_hostname].
|
|
1592
1596
|
attr_accessor :verify_hostname
|
|
1593
1597
|
|
|
1594
1598
|
# Returns the X509 certificate chain (an array of strings)
|
|
@@ -1676,7 +1680,9 @@ module Net #:nodoc:
|
|
|
1676
1680
|
begin
|
|
1677
1681
|
s = timeouted_connect(conn_addr, conn_port)
|
|
1678
1682
|
rescue => e
|
|
1679
|
-
|
|
1683
|
+
if (defined?(IO::TimeoutError) && e.is_a?(IO::TimeoutError)) || e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions
|
|
1684
|
+
e = Net::OpenTimeout.new(e)
|
|
1685
|
+
end
|
|
1680
1686
|
raise e, "Failed to open TCP connection to " +
|
|
1681
1687
|
"#{conn_addr}:#{conn_port} (#{e.message})"
|
|
1682
1688
|
end
|
|
@@ -2099,6 +2105,25 @@ module Net #:nodoc:
|
|
|
2099
2105
|
send_entity(path, data, initheader, dest, Patch, &block)
|
|
2100
2106
|
end
|
|
2101
2107
|
|
|
2108
|
+
# Sends a QUERY request to the server;
|
|
2109
|
+
# returns an instance of a subclass of Net::HTTPResponse.
|
|
2110
|
+
#
|
|
2111
|
+
# The request is based on the Net::HTTP::Query object
|
|
2112
|
+
# created from string +path+, string +data+, and initial headers hash +initheader+.
|
|
2113
|
+
#
|
|
2114
|
+
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
|
|
2115
|
+
# http = Net::HTTP.new(hostname)
|
|
2116
|
+
# http.query('/todos/1', data) # => #<Net::HTTPOK 200 OK readbody=true>
|
|
2117
|
+
#
|
|
2118
|
+
# Related:
|
|
2119
|
+
#
|
|
2120
|
+
# - Net::HTTP::Query: request class for \HTTP method QUERY.
|
|
2121
|
+
# - Net::HTTP.query: sends QUERY request, returns response body.
|
|
2122
|
+
#
|
|
2123
|
+
def query(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
|
|
2124
|
+
send_entity(path, data, initheader, dest, Query, &block)
|
|
2125
|
+
end
|
|
2126
|
+
|
|
2102
2127
|
# Sends a PUT request to the server;
|
|
2103
2128
|
# returns an instance of a subclass of Net::HTTPResponse.
|
|
2104
2129
|
#
|
|
@@ -2333,6 +2358,36 @@ module Net #:nodoc:
|
|
|
2333
2358
|
request Put.new(path, initheader), data, &block
|
|
2334
2359
|
end
|
|
2335
2360
|
|
|
2361
|
+
# Sends a QUERY request to the server;
|
|
2362
|
+
# returns an instance of a subclass of Net::HTTPResponse.
|
|
2363
|
+
#
|
|
2364
|
+
# The request is based on the Net::HTTP::Query object
|
|
2365
|
+
# created from string +path+, string +body+, and initial headers hash +initheader+.
|
|
2366
|
+
#
|
|
2367
|
+
# http = Net::HTTP.new(hostname)
|
|
2368
|
+
# http.query('/todos/1', 'xyzzy')
|
|
2369
|
+
# # => #<Net::HTTPOK 200 OK readbody=true>
|
|
2370
|
+
#
|
|
2371
|
+
# With no block given, returns the response object:
|
|
2372
|
+
#
|
|
2373
|
+
# http = Net::HTTP.new(hostname)
|
|
2374
|
+
# http.request_query('/todos') # => #<Net::HTTPOK 200 OK readbody=true>
|
|
2375
|
+
#
|
|
2376
|
+
# With a block given, calls the block with the response object
|
|
2377
|
+
# and returns the response object:
|
|
2378
|
+
#
|
|
2379
|
+
# http.request_query('/todos') do |res|
|
|
2380
|
+
# p res
|
|
2381
|
+
# end # => #<Net::HTTPOK 200 OK readbody=true>
|
|
2382
|
+
#
|
|
2383
|
+
# Output:
|
|
2384
|
+
#
|
|
2385
|
+
# #<Net::HTTPOK 200 OK readbody=false>
|
|
2386
|
+
#
|
|
2387
|
+
def request_query(path, data, initheader = nil, &block) # :yield: +response+
|
|
2388
|
+
request Query.new(path, initheader), data, &block
|
|
2389
|
+
end
|
|
2390
|
+
|
|
2336
2391
|
alias get2 request_get #:nodoc: obsolete
|
|
2337
2392
|
alias head2 request_head #:nodoc: obsolete
|
|
2338
2393
|
alias post2 request_post #:nodoc: obsolete
|
|
@@ -2428,7 +2483,7 @@ module Net #:nodoc:
|
|
|
2428
2483
|
|
|
2429
2484
|
# :stopdoc:
|
|
2430
2485
|
|
|
2431
|
-
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE
|
|
2486
|
+
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE QUERY/.freeze # :nodoc:
|
|
2432
2487
|
|
|
2433
2488
|
def transport_request(req)
|
|
2434
2489
|
count = 0
|
|
@@ -2442,11 +2497,17 @@ module Net #:nodoc:
|
|
|
2442
2497
|
# still read the received response.
|
|
2443
2498
|
end
|
|
2444
2499
|
|
|
2500
|
+
informational_count = 0
|
|
2445
2501
|
begin
|
|
2446
2502
|
res = HTTPResponse.read_new(@socket)
|
|
2447
2503
|
res.decode_content = req.decode_content
|
|
2448
2504
|
res.body_encoding = @response_body_encoding
|
|
2449
2505
|
res.ignore_eof = @ignore_eof
|
|
2506
|
+
if res.kind_of?(HTTPInformation)
|
|
2507
|
+
informational_count += 1
|
|
2508
|
+
raise HTTPBadResponse, 'too many informational responses' if
|
|
2509
|
+
informational_count > HTTPResponse::MAX_INFORMATIONAL_RESPONSES
|
|
2510
|
+
end
|
|
2450
2511
|
end while res.kind_of?(HTTPInformation)
|
|
2451
2512
|
|
|
2452
2513
|
res.uri = req.uri
|
data/sig/manifest.yaml
ADDED