net-http 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +0 -7
- data/doc/net-http/examples.rdoc +2 -1
- data/doc/net-http/included_getters.rdoc +3 -0
- data/lib/net/http/backward.rb +1 -1
- data/lib/net/http/exceptions.rb +1 -1
- data/lib/net/http/generic_request.rb +91 -15
- data/lib/net/http/header.rb +273 -117
- data/lib/net/http/proxy_delta.rb +1 -1
- data/lib/net/http/request.rb +50 -5
- data/lib/net/http/requests.rb +31 -1
- data/lib/net/http/response.rb +42 -22
- data/lib/net/http/responses.rb +931 -69
- data/lib/net/http/status.rb +7 -6
- data/lib/net/http.rb +1162 -445
- data/lib/net/https.rb +1 -1
- data/net-http.gemspec +9 -4
- metadata +4 -6
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/test.yml +0 -22
- data/.gitignore +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a746ed42ea9e1e34ae2ae72383484b19ef4537fcf60a01cd92d17604573bd3b4
|
4
|
+
data.tar.gz: 4372f3a8601b83819d8f202af095bfbd2f4e3337e808c6e3488fba37e5b3c477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d42a16ac4309c1098bedf5bece45574cb19aec58b447defebb8f448c09a9398057086e508d8f88ee05fd91e8cf87d39126d973ec83a565fd3fb96e6f1fd7a2
|
7
|
+
data.tar.gz: ffd03e1e3db77772c38a31f00a10102c07ca1814c3572ceaec664a0bc03d7c8bac8a8bb5953e6603bf5f0b1d054bce6a565ee8a19810059a78e7731f26807f2d
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -7,11 +7,4 @@ 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/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
|
-
|
17
10
|
task :default => :test
|
data/doc/net-http/examples.rdoc
CHANGED
@@ -10,9 +10,10 @@ Many code examples here use these example websites:
|
|
10
10
|
|
11
11
|
Some examples also assume these variables:
|
12
12
|
|
13
|
-
uri = URI('https://jsonplaceholder.typicode.com')
|
13
|
+
uri = URI('https://jsonplaceholder.typicode.com/')
|
14
14
|
uri.freeze # Examples may not modify.
|
15
15
|
hostname = uri.hostname # => "jsonplaceholder.typicode.com"
|
16
|
+
path = uri.path # => "/"
|
16
17
|
port = uri.port # => 443
|
17
18
|
|
18
19
|
So that example requests may be written as:
|
data/lib/net/http/backward.rb
CHANGED
data/lib/net/http/exceptions.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
# frozen_string_literal:
|
2
|
-
# HTTPGenericRequest is the parent of the Net::HTTPRequest class.
|
3
|
-
# Do not use this directly; use a subclass of Net::HTTPRequest.
|
1
|
+
# frozen_string_literal: true
|
4
2
|
#
|
5
|
-
#
|
3
|
+
# \HTTPGenericRequest is the parent of the Net::HTTPRequest class.
|
4
|
+
#
|
5
|
+
# Do not use this directly; instead, use a subclass of Net::HTTPRequest.
|
6
|
+
#
|
7
|
+
# == About the Examples
|
8
|
+
#
|
9
|
+
# :include: doc/net-http/examples.rdoc
|
6
10
|
#
|
7
11
|
class Net::HTTPGenericRequest
|
8
12
|
|
9
13
|
include Net::HTTPHeader
|
10
14
|
|
11
|
-
def initialize(m, reqbody, resbody, uri_or_path, initheader = nil)
|
15
|
+
def initialize(m, reqbody, resbody, uri_or_path, initheader = nil) # :nodoc:
|
12
16
|
@method = m
|
13
17
|
@request_has_body = reqbody
|
14
18
|
@response_has_body = resbody
|
@@ -19,7 +23,7 @@ class Net::HTTPGenericRequest
|
|
19
23
|
raise ArgumentError, "no host component for URI" unless (hostname && hostname.length > 0)
|
20
24
|
@uri = uri_or_path.dup
|
21
25
|
host = @uri.hostname.dup
|
22
|
-
host << ":"
|
26
|
+
host << ":" << @uri.port.to_s if @uri.port != @uri.default_port
|
23
27
|
@path = uri_or_path.request_uri
|
24
28
|
raise ArgumentError, "no HTTP request path given" unless @path
|
25
29
|
else
|
@@ -53,15 +57,47 @@ class Net::HTTPGenericRequest
|
|
53
57
|
@body_data = nil
|
54
58
|
end
|
55
59
|
|
60
|
+
# Returns the string method name for the request:
|
61
|
+
#
|
62
|
+
# Net::HTTP::Get.new(uri).method # => "GET"
|
63
|
+
# Net::HTTP::Post.new(uri).method # => "POST"
|
64
|
+
#
|
56
65
|
attr_reader :method
|
66
|
+
|
67
|
+
# Returns the string path for the request:
|
68
|
+
#
|
69
|
+
# Net::HTTP::Get.new(uri).path # => "/"
|
70
|
+
# Net::HTTP::Post.new('example.com').path # => "example.com"
|
71
|
+
#
|
57
72
|
attr_reader :path
|
73
|
+
|
74
|
+
# Returns the URI object for the request, or +nil+ if none:
|
75
|
+
#
|
76
|
+
# Net::HTTP::Get.new(uri).uri
|
77
|
+
# # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
|
78
|
+
# Net::HTTP::Get.new('example.com').uri # => nil
|
79
|
+
#
|
58
80
|
attr_reader :uri
|
59
81
|
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
82
|
+
# Returns +false+ if the request's header <tt>'Accept-Encoding'</tt>
|
83
|
+
# has been set manually or deleted
|
84
|
+
# (indicating that the user intends to handle encoding in the response),
|
85
|
+
# +true+ otherwise:
|
86
|
+
#
|
87
|
+
# req = Net::HTTP::Get.new(uri) # => #<Net::HTTP::Get GET>
|
88
|
+
# req['Accept-Encoding'] # => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
|
89
|
+
# req.decode_content # => true
|
90
|
+
# req['Accept-Encoding'] = 'foo'
|
91
|
+
# req.decode_content # => false
|
92
|
+
# req.delete('Accept-Encoding')
|
93
|
+
# req.decode_content # => false
|
94
|
+
#
|
63
95
|
attr_reader :decode_content
|
64
96
|
|
97
|
+
# Returns a string representation of the request:
|
98
|
+
#
|
99
|
+
# Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
|
100
|
+
#
|
65
101
|
def inspect
|
66
102
|
"\#<#{self.class} #{@method}>"
|
67
103
|
end
|
@@ -76,21 +112,45 @@ class Net::HTTPGenericRequest
|
|
76
112
|
super key, val
|
77
113
|
end
|
78
114
|
|
115
|
+
# Returns whether the request may have a body:
|
116
|
+
#
|
117
|
+
# Net::HTTP::Post.new(uri).request_body_permitted? # => true
|
118
|
+
# Net::HTTP::Get.new(uri).request_body_permitted? # => false
|
119
|
+
#
|
79
120
|
def request_body_permitted?
|
80
121
|
@request_has_body
|
81
122
|
end
|
82
123
|
|
124
|
+
# Returns whether the response may have a body:
|
125
|
+
#
|
126
|
+
# Net::HTTP::Post.new(uri).response_body_permitted? # => true
|
127
|
+
# Net::HTTP::Head.new(uri).response_body_permitted? # => false
|
128
|
+
#
|
83
129
|
def response_body_permitted?
|
84
130
|
@response_has_body
|
85
131
|
end
|
86
132
|
|
87
|
-
def body_exist?
|
133
|
+
def body_exist? # :nodoc:
|
88
134
|
warn "Net::HTTPRequest#body_exist? is obsolete; use response_body_permitted?", uplevel: 1 if $VERBOSE
|
89
135
|
response_body_permitted?
|
90
136
|
end
|
91
137
|
|
138
|
+
# Returns the string body for the request, or +nil+ if there is none:
|
139
|
+
#
|
140
|
+
# req = Net::HTTP::Post.new(uri)
|
141
|
+
# req.body # => nil
|
142
|
+
# req.body = '{"title": "foo","body": "bar","userId": 1}'
|
143
|
+
# req.body # => "{\"title\": \"foo\",\"body\": \"bar\",\"userId\": 1}"
|
144
|
+
#
|
92
145
|
attr_reader :body
|
93
146
|
|
147
|
+
# Sets the body for the request:
|
148
|
+
#
|
149
|
+
# req = Net::HTTP::Post.new(uri)
|
150
|
+
# req.body # => nil
|
151
|
+
# req.body = '{"title": "foo","body": "bar","userId": 1}'
|
152
|
+
# req.body # => "{\"title\": \"foo\",\"body\": \"bar\",\"userId\": 1}"
|
153
|
+
#
|
94
154
|
def body=(str)
|
95
155
|
@body = str
|
96
156
|
@body_stream = nil
|
@@ -98,8 +158,24 @@ class Net::HTTPGenericRequest
|
|
98
158
|
str
|
99
159
|
end
|
100
160
|
|
161
|
+
# Returns the body stream object for the request, or +nil+ if there is none:
|
162
|
+
#
|
163
|
+
# req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
|
164
|
+
# req.body_stream # => nil
|
165
|
+
# require 'stringio'
|
166
|
+
# req.body_stream = StringIO.new('xyzzy') # => #<StringIO:0x0000027d1e5affa8>
|
167
|
+
# req.body_stream # => #<StringIO:0x0000027d1e5affa8>
|
168
|
+
#
|
101
169
|
attr_reader :body_stream
|
102
170
|
|
171
|
+
# Sets the body stream for the request:
|
172
|
+
#
|
173
|
+
# req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
|
174
|
+
# req.body_stream # => nil
|
175
|
+
# require 'stringio'
|
176
|
+
# req.body_stream = StringIO.new('xyzzy') # => #<StringIO:0x0000027d1e5affa8>
|
177
|
+
# req.body_stream # => #<StringIO:0x0000027d1e5affa8>
|
178
|
+
#
|
103
179
|
def body_stream=(input)
|
104
180
|
@body = nil
|
105
181
|
@body_stream = input
|
@@ -136,15 +212,15 @@ class Net::HTTPGenericRequest
|
|
136
212
|
return unless @uri
|
137
213
|
|
138
214
|
if ssl
|
139
|
-
scheme = 'https'
|
215
|
+
scheme = 'https'
|
140
216
|
klass = URI::HTTPS
|
141
217
|
else
|
142
|
-
scheme = 'http'
|
218
|
+
scheme = 'http'
|
143
219
|
klass = URI::HTTP
|
144
220
|
end
|
145
221
|
|
146
222
|
if host = self['host']
|
147
|
-
host.sub!(/:.*/m, ''
|
223
|
+
host.sub!(/:.*/m, '')
|
148
224
|
elsif host = @uri.host
|
149
225
|
else
|
150
226
|
host = addr
|
@@ -240,7 +316,7 @@ class Net::HTTPGenericRequest
|
|
240
316
|
boundary ||= SecureRandom.urlsafe_base64(40)
|
241
317
|
chunked_p = chunked?
|
242
318
|
|
243
|
-
buf = ''
|
319
|
+
buf = +''
|
244
320
|
params.each do |key, value, h={}|
|
245
321
|
key = quote_string(key, charset)
|
246
322
|
filename =
|
@@ -325,7 +401,7 @@ class Net::HTTPGenericRequest
|
|
325
401
|
if /[\r\n]/ =~ reqline
|
326
402
|
raise ArgumentError, "A Request-Line must not contain CR or LF"
|
327
403
|
end
|
328
|
-
buf =
|
404
|
+
buf = +''
|
329
405
|
buf << reqline << "\r\n"
|
330
406
|
each_capitalized do |k,v|
|
331
407
|
buf << "#{k}: #{v}\r\n"
|