net-http 0.3.2 → 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 +164 -67
- 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 +507 -55
- data/lib/net/http/status.rb +7 -6
- data/lib/net/http.rb +944 -464
- 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
data/lib/net/http/requests.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# HTTP/1.1 methods --- RFC2616
|
4
4
|
|
@@ -13,6 +13,8 @@
|
|
13
13
|
# http.request(req)
|
14
14
|
# end
|
15
15
|
#
|
16
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
17
|
+
#
|
16
18
|
# Properties:
|
17
19
|
#
|
18
20
|
# - Request body: optional.
|
@@ -43,6 +45,8 @@ end
|
|
43
45
|
# http.request(req)
|
44
46
|
# end
|
45
47
|
#
|
48
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
49
|
+
#
|
46
50
|
# Properties:
|
47
51
|
#
|
48
52
|
# - Request body: optional.
|
@@ -75,6 +79,8 @@ end
|
|
75
79
|
# http.request(req)
|
76
80
|
# end
|
77
81
|
#
|
82
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
83
|
+
#
|
78
84
|
# Properties:
|
79
85
|
#
|
80
86
|
# - Request body: yes.
|
@@ -108,6 +114,8 @@ end
|
|
108
114
|
# http.request(req)
|
109
115
|
# end
|
110
116
|
#
|
117
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
118
|
+
#
|
111
119
|
# Properties:
|
112
120
|
#
|
113
121
|
# - Request body: yes.
|
@@ -134,6 +142,8 @@ end
|
|
134
142
|
# http.request(req)
|
135
143
|
# end
|
136
144
|
#
|
145
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
146
|
+
#
|
137
147
|
# Properties:
|
138
148
|
#
|
139
149
|
# - Request body: optional.
|
@@ -163,6 +173,8 @@ end
|
|
163
173
|
# http.request(req)
|
164
174
|
# end
|
165
175
|
#
|
176
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
177
|
+
#
|
166
178
|
# Properties:
|
167
179
|
#
|
168
180
|
# - Request body: optional.
|
@@ -192,6 +204,8 @@ end
|
|
192
204
|
# http.request(req)
|
193
205
|
# end
|
194
206
|
#
|
207
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
208
|
+
#
|
195
209
|
# Properties:
|
196
210
|
#
|
197
211
|
# - Request body: no.
|
@@ -224,6 +238,8 @@ end
|
|
224
238
|
# http.request(req)
|
225
239
|
# end
|
226
240
|
#
|
241
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
242
|
+
#
|
227
243
|
# Properties:
|
228
244
|
#
|
229
245
|
# - Request body: yes.
|
@@ -257,6 +273,8 @@ end
|
|
257
273
|
# http.request(req)
|
258
274
|
# end
|
259
275
|
#
|
276
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
277
|
+
#
|
260
278
|
# Related:
|
261
279
|
#
|
262
280
|
# - Net::HTTP#propfind: sends +PROPFIND+ request, returns response object.
|
@@ -278,6 +296,8 @@ end
|
|
278
296
|
# http.request(req)
|
279
297
|
# end
|
280
298
|
#
|
299
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
300
|
+
#
|
281
301
|
# Related:
|
282
302
|
#
|
283
303
|
# - Net::HTTP#proppatch: sends +PROPPATCH+ request, returns response object.
|
@@ -299,6 +319,8 @@ end
|
|
299
319
|
# http.request(req)
|
300
320
|
# end
|
301
321
|
#
|
322
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
323
|
+
#
|
302
324
|
# Related:
|
303
325
|
#
|
304
326
|
# - Net::HTTP#mkcol: sends +MKCOL+ request, returns response object.
|
@@ -320,6 +342,8 @@ end
|
|
320
342
|
# http.request(req)
|
321
343
|
# end
|
322
344
|
#
|
345
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
346
|
+
#
|
323
347
|
# Related:
|
324
348
|
#
|
325
349
|
# - Net::HTTP#copy: sends +COPY+ request, returns response object.
|
@@ -341,6 +365,8 @@ end
|
|
341
365
|
# http.request(req)
|
342
366
|
# end
|
343
367
|
#
|
368
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
369
|
+
#
|
344
370
|
# Related:
|
345
371
|
#
|
346
372
|
# - Net::HTTP#move: sends +MOVE+ request, returns response object.
|
@@ -362,6 +388,8 @@ end
|
|
362
388
|
# http.request(req)
|
363
389
|
# end
|
364
390
|
#
|
391
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
392
|
+
#
|
365
393
|
# Related:
|
366
394
|
#
|
367
395
|
# - Net::HTTP#lock: sends +LOCK+ request, returns response object.
|
@@ -383,6 +411,8 @@ end
|
|
383
411
|
# http.request(req)
|
384
412
|
# end
|
385
413
|
#
|
414
|
+
# See {Request Headers}[rdoc-ref:Net::HTTPRequest@Request+Headers].
|
415
|
+
#
|
386
416
|
# Related:
|
387
417
|
#
|
388
418
|
# - Net::HTTP#unlock: sends +UNLOCK+ request, returns response object.
|
data/lib/net/http/response.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# This class is the base class for \Net::HTTP
|
3
|
+
# This class is the base class for \Net::HTTP response classes.
|
4
4
|
#
|
5
5
|
# == About the Examples
|
6
6
|
#
|
@@ -224,13 +224,32 @@ class Net::HTTPResponse
|
|
224
224
|
# Accept-Encoding header from the user.
|
225
225
|
attr_accessor :decode_content
|
226
226
|
|
227
|
-
#
|
228
|
-
#
|
229
|
-
# that.
|
227
|
+
# Returns the value set by body_encoding=, or +false+ if none;
|
228
|
+
# see #body_encoding=.
|
230
229
|
attr_reader :body_encoding
|
231
230
|
|
232
|
-
#
|
233
|
-
#
|
231
|
+
# Sets the encoding that should be used when reading the body:
|
232
|
+
#
|
233
|
+
# - If the given value is an Encoding object, that encoding will be used.
|
234
|
+
# - Otherwise if the value is a string, the value of
|
235
|
+
# {Encoding#find(value)}[https://docs.ruby-lang.org/en/master/Encoding.html#method-c-find]
|
236
|
+
# will be used.
|
237
|
+
# - Otherwise an encoding will be deduced from the body itself.
|
238
|
+
#
|
239
|
+
# Examples:
|
240
|
+
#
|
241
|
+
# http = Net::HTTP.new(hostname)
|
242
|
+
# req = Net::HTTP::Get.new('/')
|
243
|
+
#
|
244
|
+
# http.request(req) do |res|
|
245
|
+
# p res.body.encoding # => #<Encoding:ASCII-8BIT>
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
# http.request(req) do |res|
|
249
|
+
# res.body_encoding = "UTF-8"
|
250
|
+
# p res.body.encoding # => #<Encoding:UTF-8>
|
251
|
+
# end
|
252
|
+
#
|
234
253
|
def body_encoding=(value)
|
235
254
|
value = Encoding.find(value) if value.is_a?(String)
|
236
255
|
@body_encoding = value
|
@@ -254,7 +273,7 @@ class Net::HTTPResponse
|
|
254
273
|
|
255
274
|
def error! #:nodoc:
|
256
275
|
message = @code
|
257
|
-
message
|
276
|
+
message = "#{message} #{@message.dump}" if @message
|
258
277
|
raise error_type().new(message, self)
|
259
278
|
end
|
260
279
|
|
@@ -347,6 +366,7 @@ class Net::HTTPResponse
|
|
347
366
|
@body = nil
|
348
367
|
end
|
349
368
|
@read = true
|
369
|
+
return if @body.nil?
|
350
370
|
|
351
371
|
case enc = @body_encoding
|
352
372
|
when Encoding, false, nil
|
@@ -362,26 +382,26 @@ class Net::HTTPResponse
|
|
362
382
|
@body
|
363
383
|
end
|
364
384
|
|
365
|
-
# Returns the
|
385
|
+
# Returns the string response body;
|
386
|
+
# note that repeated calls for the unmodified body return a cached string:
|
366
387
|
#
|
367
|
-
#
|
368
|
-
#
|
388
|
+
# path = '/todos/1'
|
389
|
+
# Net::HTTP.start(hostname) do |http|
|
390
|
+
# res = http.get(path)
|
391
|
+
# p res.body
|
392
|
+
# p http.head(path).body # No body.
|
393
|
+
# end
|
369
394
|
#
|
370
|
-
#
|
371
|
-
# puts res.body
|
372
|
-
# }
|
395
|
+
# Output:
|
373
396
|
#
|
374
|
-
#
|
375
|
-
#
|
376
|
-
# p res.body.object_id # 538149362
|
377
|
-
# }
|
397
|
+
# "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}"
|
398
|
+
# nil
|
378
399
|
#
|
379
400
|
def body
|
380
401
|
read_body()
|
381
402
|
end
|
382
403
|
|
383
|
-
#
|
384
|
-
# this method facilitates that.
|
404
|
+
# Sets the body of the response to the given value.
|
385
405
|
def body=(value)
|
386
406
|
@body = value
|
387
407
|
end
|
@@ -620,7 +640,7 @@ class Net::HTTPResponse
|
|
620
640
|
end
|
621
641
|
|
622
642
|
def stream_check
|
623
|
-
raise IOError, 'attempt to read body out of block' if @socket.closed?
|
643
|
+
raise IOError, 'attempt to read body out of block' if @socket.nil? || @socket.closed?
|
624
644
|
end
|
625
645
|
|
626
646
|
def procdest(dest, block)
|
@@ -629,7 +649,7 @@ class Net::HTTPResponse
|
|
629
649
|
if block
|
630
650
|
Net::ReadAdapter.new(block)
|
631
651
|
else
|
632
|
-
dest || ''
|
652
|
+
dest || +''
|
633
653
|
end
|
634
654
|
end
|
635
655
|
|