net-http 0.3.0 → 0.3.1
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/.gitignore +0 -1
- data/doc/net-http/examples.rdoc +30 -0
- data/lib/net/http/header.rb +381 -73
- data/lib/net/http/request.rb +27 -5
- data/lib/net/http/requests.rb +296 -24
- data/lib/net/http/response.rb +127 -11
- data/lib/net/http.rb +311 -295
- metadata +3 -2
data/lib/net/http/requests.rb
CHANGED
@@ -1,67 +1,241 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
|
2
|
+
|
3
3
|
# HTTP/1.1 methods --- RFC2616
|
4
|
-
#
|
5
4
|
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# \Class for representing
|
6
|
+
# {HTTP method GET}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#GET_method]:
|
7
|
+
#
|
8
|
+
# require 'net/http'
|
9
|
+
# uri = URI('http://example.com')
|
10
|
+
# hostname = uri.hostname # => "example.com"
|
11
|
+
# req = Net::HTTP::Get.new(uri) # => #<Net::HTTP::Get GET>
|
12
|
+
# res = Net::HTTP.start(hostname) do |http|
|
13
|
+
# http.request(req)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Properties:
|
17
|
+
#
|
18
|
+
# - Request body: optional.
|
19
|
+
# - Response body: yes.
|
20
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
|
21
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
22
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
|
23
|
+
#
|
24
|
+
# Related:
|
25
|
+
#
|
26
|
+
# - Net::HTTP.get: sends +GET+ request, returns response body.
|
27
|
+
# - Net::HTTP#get: sends +GET+ request, returns response object.
|
28
|
+
#
|
8
29
|
class Net::HTTP::Get < Net::HTTPRequest
|
9
30
|
METHOD = 'GET'
|
10
31
|
REQUEST_HAS_BODY = false
|
11
32
|
RESPONSE_HAS_BODY = true
|
12
33
|
end
|
13
34
|
|
14
|
-
#
|
15
|
-
#
|
35
|
+
# \Class for representing
|
36
|
+
# {HTTP method HEAD}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#HEAD_method]:
|
37
|
+
#
|
38
|
+
# require 'net/http'
|
39
|
+
# uri = URI('http://example.com')
|
40
|
+
# hostname = uri.hostname # => "example.com"
|
41
|
+
# req = Net::HTTP::Head.new(uri) # => #<Net::HTTP::Head HEAD>
|
42
|
+
# res = Net::HTTP.start(hostname) do |http|
|
43
|
+
# http.request(req)
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# Properties:
|
47
|
+
#
|
48
|
+
# - Request body: optional.
|
49
|
+
# - Response body: no.
|
50
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
|
51
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
52
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
|
53
|
+
#
|
54
|
+
# Related:
|
55
|
+
#
|
56
|
+
# - Net::HTTP#head: sends +HEAD+ request, returns response object.
|
57
|
+
#
|
16
58
|
class Net::HTTP::Head < Net::HTTPRequest
|
17
59
|
METHOD = 'HEAD'
|
18
60
|
REQUEST_HAS_BODY = false
|
19
61
|
RESPONSE_HAS_BODY = false
|
20
62
|
end
|
21
63
|
|
22
|
-
#
|
23
|
-
#
|
64
|
+
# \Class for representing
|
65
|
+
# {HTTP method POST}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#POST_method]:
|
66
|
+
#
|
67
|
+
# require 'net/http'
|
68
|
+
# uri = URI('http://example.com')
|
69
|
+
# hostname = uri.hostname # => "example.com"
|
70
|
+
# uri.path = '/posts'
|
71
|
+
# req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
|
72
|
+
# req.body = '{"title": "foo","body": "bar","userId": 1}'
|
73
|
+
# req.content_type = 'application/json'
|
74
|
+
# res = Net::HTTP.start(hostname) do |http|
|
75
|
+
# http.request(req)
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# Properties:
|
79
|
+
#
|
80
|
+
# - Request body: yes.
|
81
|
+
# - Response body: yes.
|
82
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
|
83
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: no.
|
84
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
|
85
|
+
#
|
86
|
+
# Related:
|
87
|
+
#
|
88
|
+
# - Net::HTTP.post: sends +POST+ request, returns response object.
|
89
|
+
# - Net::HTTP#post: sends +POST+ request, returns response object.
|
90
|
+
#
|
24
91
|
class Net::HTTP::Post < Net::HTTPRequest
|
25
92
|
METHOD = 'POST'
|
26
93
|
REQUEST_HAS_BODY = true
|
27
94
|
RESPONSE_HAS_BODY = true
|
28
95
|
end
|
29
96
|
|
30
|
-
#
|
31
|
-
#
|
97
|
+
# \Class for representing
|
98
|
+
# {HTTP method PUT}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PUT_method]:
|
99
|
+
#
|
100
|
+
# require 'net/http'
|
101
|
+
# uri = URI('http://example.com')
|
102
|
+
# hostname = uri.hostname # => "example.com"
|
103
|
+
# uri.path = '/posts'
|
104
|
+
# req = Net::HTTP::Put.new(uri) # => #<Net::HTTP::Put PUT>
|
105
|
+
# req.body = '{"title": "foo","body": "bar","userId": 1}'
|
106
|
+
# req.content_type = 'application/json'
|
107
|
+
# res = Net::HTTP.start(hostname) do |http|
|
108
|
+
# http.request(req)
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# Properties:
|
112
|
+
#
|
113
|
+
# - Request body: yes.
|
114
|
+
# - Response body: yes.
|
115
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
|
116
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
117
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
|
118
|
+
#
|
32
119
|
class Net::HTTP::Put < Net::HTTPRequest
|
33
120
|
METHOD = 'PUT'
|
34
121
|
REQUEST_HAS_BODY = true
|
35
122
|
RESPONSE_HAS_BODY = true
|
36
123
|
end
|
37
124
|
|
38
|
-
#
|
39
|
-
#
|
125
|
+
# \Class for representing
|
126
|
+
# {HTTP method DELETE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#DELETE_method]:
|
127
|
+
#
|
128
|
+
# require 'net/http'
|
129
|
+
# uri = URI('http://example.com')
|
130
|
+
# hostname = uri.hostname # => "example.com"
|
131
|
+
# uri.path = '/posts/1'
|
132
|
+
# req = Net::HTTP::Delete.new(uri) # => #<Net::HTTP::Delete DELETE>
|
133
|
+
# res = Net::HTTP.start(hostname) do |http|
|
134
|
+
# http.request(req)
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# Properties:
|
138
|
+
#
|
139
|
+
# - Request body: optional.
|
140
|
+
# - Response body: yes.
|
141
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
|
142
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
143
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
|
144
|
+
#
|
145
|
+
# Related:
|
146
|
+
#
|
147
|
+
# - Net::HTTP#delete: sends +DELETE+ request, returns response object.
|
148
|
+
#
|
40
149
|
class Net::HTTP::Delete < Net::HTTPRequest
|
41
150
|
METHOD = 'DELETE'
|
42
151
|
REQUEST_HAS_BODY = false
|
43
152
|
RESPONSE_HAS_BODY = true
|
44
153
|
end
|
45
154
|
|
46
|
-
#
|
155
|
+
# \Class for representing
|
156
|
+
# {HTTP method OPTIONS}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#OPTIONS_method]:
|
157
|
+
#
|
158
|
+
# require 'net/http'
|
159
|
+
# uri = URI('http://example.com')
|
160
|
+
# hostname = uri.hostname # => "example.com"
|
161
|
+
# req = Net::HTTP::Options.new(uri) # => #<Net::HTTP::Options OPTIONS>
|
162
|
+
# res = Net::HTTP.start(hostname) do |http|
|
163
|
+
# http.request(req)
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# Properties:
|
167
|
+
#
|
168
|
+
# - Request body: optional.
|
169
|
+
# - Response body: yes.
|
170
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
|
171
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
172
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
|
173
|
+
#
|
174
|
+
# Related:
|
175
|
+
#
|
176
|
+
# - Net::HTTP#options: sends +OPTIONS+ request, returns response object.
|
177
|
+
#
|
47
178
|
class Net::HTTP::Options < Net::HTTPRequest
|
48
179
|
METHOD = 'OPTIONS'
|
49
180
|
REQUEST_HAS_BODY = false
|
50
181
|
RESPONSE_HAS_BODY = true
|
51
182
|
end
|
52
183
|
|
53
|
-
#
|
184
|
+
# \Class for representing
|
185
|
+
# {HTTP method TRACE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#TRACE_method]:
|
186
|
+
#
|
187
|
+
# require 'net/http'
|
188
|
+
# uri = URI('http://example.com')
|
189
|
+
# hostname = uri.hostname # => "example.com"
|
190
|
+
# req = Net::HTTP::Trace.new(uri) # => #<Net::HTTP::Trace TRACE>
|
191
|
+
# res = Net::HTTP.start(hostname) do |http|
|
192
|
+
# http.request(req)
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# Properties:
|
196
|
+
#
|
197
|
+
# - Request body: no.
|
198
|
+
# - Response body: yes.
|
199
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
|
200
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
|
201
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
|
202
|
+
#
|
203
|
+
# Related:
|
204
|
+
#
|
205
|
+
# - Net::HTTP#trace: sends +TRACE+ request, returns response object.
|
206
|
+
#
|
54
207
|
class Net::HTTP::Trace < Net::HTTPRequest
|
55
208
|
METHOD = 'TRACE'
|
56
209
|
REQUEST_HAS_BODY = false
|
57
210
|
RESPONSE_HAS_BODY = true
|
58
211
|
end
|
59
212
|
|
213
|
+
# \Class for representing
|
214
|
+
# {HTTP method PATCH}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PATCH_method]:
|
60
215
|
#
|
61
|
-
#
|
216
|
+
# require 'net/http'
|
217
|
+
# uri = URI('http://example.com')
|
218
|
+
# hostname = uri.hostname # => "example.com"
|
219
|
+
# uri.path = '/posts'
|
220
|
+
# req = Net::HTTP::Patch.new(uri) # => #<Net::HTTP::Patch PATCH>
|
221
|
+
# req.body = '{"title": "foo","body": "bar","userId": 1}'
|
222
|
+
# req.content_type = 'application/json'
|
223
|
+
# res = Net::HTTP.start(hostname) do |http|
|
224
|
+
# http.request(req)
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# Properties:
|
228
|
+
#
|
229
|
+
# - Request body: yes.
|
230
|
+
# - Response body: yes.
|
231
|
+
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
|
232
|
+
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: no.
|
233
|
+
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
|
234
|
+
#
|
235
|
+
# Related:
|
236
|
+
#
|
237
|
+
# - Net::HTTP#patch: sends +PATCH+ request, returns response object.
|
62
238
|
#
|
63
|
-
|
64
|
-
# See Net::HTTPGenericRequest for attributes and methods.
|
65
239
|
class Net::HTTP::Patch < Net::HTTPRequest
|
66
240
|
METHOD = 'PATCH'
|
67
241
|
REQUEST_HAS_BODY = true
|
@@ -72,49 +246,147 @@ end
|
|
72
246
|
# WebDAV methods --- RFC2518
|
73
247
|
#
|
74
248
|
|
75
|
-
#
|
249
|
+
# \Class for representing
|
250
|
+
# {WebDAV method PROPFIND}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND]:
|
251
|
+
#
|
252
|
+
# require 'net/http'
|
253
|
+
# uri = URI('http://example.com')
|
254
|
+
# hostname = uri.hostname # => "example.com"
|
255
|
+
# req = Net::HTTP::Propfind.new(uri) # => #<Net::HTTP::Propfind PROPFIND>
|
256
|
+
# res = Net::HTTP.start(hostname) do |http|
|
257
|
+
# http.request(req)
|
258
|
+
# end
|
259
|
+
#
|
260
|
+
# Related:
|
261
|
+
#
|
262
|
+
# - Net::HTTP#propfind: sends +PROPFIND+ request, returns response object.
|
263
|
+
#
|
76
264
|
class Net::HTTP::Propfind < Net::HTTPRequest
|
77
265
|
METHOD = 'PROPFIND'
|
78
266
|
REQUEST_HAS_BODY = true
|
79
267
|
RESPONSE_HAS_BODY = true
|
80
268
|
end
|
81
269
|
|
82
|
-
#
|
270
|
+
# \Class for representing
|
271
|
+
# {WebDAV method PROPPATCH}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPPATCH]:
|
272
|
+
#
|
273
|
+
# require 'net/http'
|
274
|
+
# uri = URI('http://example.com')
|
275
|
+
# hostname = uri.hostname # => "example.com"
|
276
|
+
# req = Net::HTTP::Proppatch.new(uri) # => #<Net::HTTP::Proppatch PROPPATCH>
|
277
|
+
# res = Net::HTTP.start(hostname) do |http|
|
278
|
+
# http.request(req)
|
279
|
+
# end
|
280
|
+
#
|
281
|
+
# Related:
|
282
|
+
#
|
283
|
+
# - Net::HTTP#proppatch: sends +PROPPATCH+ request, returns response object.
|
284
|
+
#
|
83
285
|
class Net::HTTP::Proppatch < Net::HTTPRequest
|
84
286
|
METHOD = 'PROPPATCH'
|
85
287
|
REQUEST_HAS_BODY = true
|
86
288
|
RESPONSE_HAS_BODY = true
|
87
289
|
end
|
88
290
|
|
89
|
-
#
|
291
|
+
# \Class for representing
|
292
|
+
# {WebDAV method MKCOL}[http://www.webdav.org/specs/rfc4918.html#METHOD_MKCOL]:
|
293
|
+
#
|
294
|
+
# require 'net/http'
|
295
|
+
# uri = URI('http://example.com')
|
296
|
+
# hostname = uri.hostname # => "example.com"
|
297
|
+
# req = Net::HTTP::Mkcol.new(uri) # => #<Net::HTTP::Mkcol MKCOL>
|
298
|
+
# res = Net::HTTP.start(hostname) do |http|
|
299
|
+
# http.request(req)
|
300
|
+
# end
|
301
|
+
#
|
302
|
+
# Related:
|
303
|
+
#
|
304
|
+
# - Net::HTTP#mkcol: sends +MKCOL+ request, returns response object.
|
305
|
+
#
|
90
306
|
class Net::HTTP::Mkcol < Net::HTTPRequest
|
91
307
|
METHOD = 'MKCOL'
|
92
308
|
REQUEST_HAS_BODY = true
|
93
309
|
RESPONSE_HAS_BODY = true
|
94
310
|
end
|
95
311
|
|
96
|
-
#
|
312
|
+
# \Class for representing
|
313
|
+
# {WebDAV method COPY}[http://www.webdav.org/specs/rfc4918.html#METHOD_COPY]:
|
314
|
+
#
|
315
|
+
# require 'net/http'
|
316
|
+
# uri = URI('http://example.com')
|
317
|
+
# hostname = uri.hostname # => "example.com"
|
318
|
+
# req = Net::HTTP::Copy.new(uri) # => #<Net::HTTP::Copy COPY>
|
319
|
+
# res = Net::HTTP.start(hostname) do |http|
|
320
|
+
# http.request(req)
|
321
|
+
# end
|
322
|
+
#
|
323
|
+
# Related:
|
324
|
+
#
|
325
|
+
# - Net::HTTP#copy: sends +COPY+ request, returns response object.
|
326
|
+
#
|
97
327
|
class Net::HTTP::Copy < Net::HTTPRequest
|
98
328
|
METHOD = 'COPY'
|
99
329
|
REQUEST_HAS_BODY = false
|
100
330
|
RESPONSE_HAS_BODY = true
|
101
331
|
end
|
102
332
|
|
103
|
-
#
|
333
|
+
# \Class for representing
|
334
|
+
# {WebDAV method MOVE}[http://www.webdav.org/specs/rfc4918.html#METHOD_MOVE]:
|
335
|
+
#
|
336
|
+
# require 'net/http'
|
337
|
+
# uri = URI('http://example.com')
|
338
|
+
# hostname = uri.hostname # => "example.com"
|
339
|
+
# req = Net::HTTP::Move.new(uri) # => #<Net::HTTP::Move MOVE>
|
340
|
+
# res = Net::HTTP.start(hostname) do |http|
|
341
|
+
# http.request(req)
|
342
|
+
# end
|
343
|
+
#
|
344
|
+
# Related:
|
345
|
+
#
|
346
|
+
# - Net::HTTP#move: sends +MOVE+ request, returns response object.
|
347
|
+
#
|
104
348
|
class Net::HTTP::Move < Net::HTTPRequest
|
105
349
|
METHOD = 'MOVE'
|
106
350
|
REQUEST_HAS_BODY = false
|
107
351
|
RESPONSE_HAS_BODY = true
|
108
352
|
end
|
109
353
|
|
110
|
-
#
|
354
|
+
# \Class for representing
|
355
|
+
# {WebDAV method LOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_LOCK]:
|
356
|
+
#
|
357
|
+
# require 'net/http'
|
358
|
+
# uri = URI('http://example.com')
|
359
|
+
# hostname = uri.hostname # => "example.com"
|
360
|
+
# req = Net::HTTP::Lock.new(uri) # => #<Net::HTTP::Lock LOCK>
|
361
|
+
# res = Net::HTTP.start(hostname) do |http|
|
362
|
+
# http.request(req)
|
363
|
+
# end
|
364
|
+
#
|
365
|
+
# Related:
|
366
|
+
#
|
367
|
+
# - Net::HTTP#lock: sends +LOCK+ request, returns response object.
|
368
|
+
#
|
111
369
|
class Net::HTTP::Lock < Net::HTTPRequest
|
112
370
|
METHOD = 'LOCK'
|
113
371
|
REQUEST_HAS_BODY = true
|
114
372
|
RESPONSE_HAS_BODY = true
|
115
373
|
end
|
116
374
|
|
117
|
-
#
|
375
|
+
# \Class for representing
|
376
|
+
# {WebDAV method UNLOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_UNLOCK]:
|
377
|
+
#
|
378
|
+
# require 'net/http'
|
379
|
+
# uri = URI('http://example.com')
|
380
|
+
# hostname = uri.hostname # => "example.com"
|
381
|
+
# req = Net::HTTP::Unlock.new(uri) # => #<Net::HTTP::Unlock UNLOCK>
|
382
|
+
# res = Net::HTTP.start(hostname) do |http|
|
383
|
+
# http.request(req)
|
384
|
+
# end
|
385
|
+
#
|
386
|
+
# Related:
|
387
|
+
#
|
388
|
+
# - Net::HTTP#unlock: sends +UNLOCK+ request, returns response object.
|
389
|
+
#
|
118
390
|
class Net::HTTP::Unlock < Net::HTTPRequest
|
119
391
|
METHOD = 'UNLOCK'
|
120
392
|
REQUEST_HAS_BODY = true
|
data/lib/net/http/response.rb
CHANGED
@@ -1,20 +1,136 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
|
-
|
2
|
+
|
3
|
+
# This class is the base class for \Net::HTTP request classes.
|
4
|
+
#
|
5
|
+
# == About the Examples
|
6
|
+
#
|
7
|
+
# :include: doc/net-http/examples.rdoc
|
8
|
+
#
|
9
|
+
# == Returned Responses
|
10
|
+
#
|
11
|
+
# \Method Net::HTTP.get_response returns
|
12
|
+
# an instance of one of the subclasses of \Net::HTTPResponse:
|
13
|
+
#
|
14
|
+
# Net::HTTP.get_response(uri)
|
15
|
+
# # => #<Net::HTTPOK 200 OK readbody=true>
|
16
|
+
# Net::HTTP.get_response(hostname, '/nosuch')
|
17
|
+
# # => #<Net::HTTPNotFound 404 Not Found readbody=true>
|
18
|
+
#
|
19
|
+
# As does method Net::HTTP#request:
|
20
|
+
#
|
21
|
+
# req = Net::HTTP::Get.new(uri)
|
22
|
+
# Net::HTTP.start(hostname) do |http|
|
23
|
+
# http.request(req)
|
24
|
+
# end # => #<Net::HTTPOK 200 OK readbody=true>
|
25
|
+
#
|
26
|
+
# \Class \Net::HTTPResponse includes module Net::HTTPHeader,
|
27
|
+
# which provides access to response header values via (among others):
|
28
|
+
#
|
29
|
+
# - \Hash-like method <tt>[]</tt>.
|
30
|
+
# - Specific reader methods, such as +content_type+.
|
31
|
+
#
|
32
|
+
# Examples:
|
33
|
+
#
|
34
|
+
# res = Net::HTTP.get_response(uri) # => #<Net::HTTPOK 200 OK readbody=true>
|
35
|
+
# res['Content-Type'] # => "text/html; charset=UTF-8"
|
36
|
+
# res.content_type # => "text/html"
|
37
|
+
#
|
38
|
+
# == Response Subclasses
|
39
|
+
#
|
40
|
+
# \Class \Net::HTTPResponse has a subclass for each
|
41
|
+
# {HTTP status code}[https://en.wikipedia.org/wiki/List_of_HTTP_status_codes].
|
42
|
+
# You can look up the response class for a given code:
|
43
|
+
#
|
44
|
+
# Net::HTTPResponse::CODE_TO_OBJ['200'] # => Net::HTTPOK
|
45
|
+
# Net::HTTPResponse::CODE_TO_OBJ['400'] # => Net::HTTPBadRequest
|
46
|
+
# Net::HTTPResponse::CODE_TO_OBJ['404'] # => Net::HTTPNotFound
|
47
|
+
#
|
48
|
+
# And you can retrieve the status code for a response object:
|
49
|
+
#
|
50
|
+
# Net::HTTP.get_response(uri).code # => "200"
|
51
|
+
# Net::HTTP.get_response(hostname, '/nosuch').code # => "404"
|
52
|
+
#
|
53
|
+
# The response subclasses (indentation shows class hierarchy):
|
54
|
+
#
|
55
|
+
# - Net::HTTPUnknownResponse (for unhandled \HTTP extensions).
|
56
|
+
#
|
57
|
+
# - Net::HTTPInformation:
|
58
|
+
#
|
59
|
+
# - Net::HTTPContinue (100)
|
60
|
+
# - Net::HTTPSwitchProtocol (101)
|
61
|
+
# - Net::HTTPProcessing (102)
|
62
|
+
# - Net::HTTPEarlyHints (103)
|
63
|
+
#
|
64
|
+
# - Net::HTTPSuccess:
|
65
|
+
#
|
66
|
+
# - Net::HTTPOK (200)
|
67
|
+
# - Net::HTTPCreated (201)
|
68
|
+
# - Net::HTTPAccepted (202)
|
69
|
+
# - Net::HTTPNonAuthoritativeInformation (203)
|
70
|
+
# - Net::HTTPNoContent (204)
|
71
|
+
# - Net::HTTPResetContent (205)
|
72
|
+
# - Net::HTTPPartialContent (206)
|
73
|
+
# - Net::HTTPMultiStatus (207)
|
74
|
+
# - Net::HTTPAlreadyReported (208)
|
75
|
+
# - Net::HTTPIMUsed (226)
|
76
|
+
#
|
77
|
+
# - Net::HTTPRedirection:
|
78
|
+
#
|
79
|
+
# - Net::HTTPMultipleChoices (300)
|
80
|
+
# - Net::HTTPMovedPermanently (301)
|
81
|
+
# - Net::HTTPFound (302)
|
82
|
+
# - Net::HTTPSeeOther (303)
|
83
|
+
# - Net::HTTPNotModified (304)
|
84
|
+
# - Net::HTTPUseProxy (305)
|
85
|
+
# - Net::HTTPTemporaryRedirect (307)
|
86
|
+
# - Net::HTTPPermanentRedirect (308)
|
3
87
|
#
|
4
|
-
#
|
5
|
-
# entity requested).
|
88
|
+
# - Net::HTTPClientError:
|
6
89
|
#
|
7
|
-
#
|
8
|
-
#
|
90
|
+
# - Net::HTTPBadRequest (400)
|
91
|
+
# - Net::HTTPUnauthorized (401)
|
92
|
+
# - Net::HTTPPaymentRequired (402)
|
93
|
+
# - Net::HTTPForbidden (403)
|
94
|
+
# - Net::HTTPNotFound (404)
|
95
|
+
# - Net::HTTPMethodNotAllowed (405)
|
96
|
+
# - Net::HTTPNotAcceptable (406)
|
97
|
+
# - Net::HTTPProxyAuthenticationRequired (407)
|
98
|
+
# - Net::HTTPRequestTimeOut (408)
|
99
|
+
# - Net::HTTPConflict (409)
|
100
|
+
# - Net::HTTPGone (410)
|
101
|
+
# - Net::HTTPLengthRequired (411)
|
102
|
+
# - Net::HTTPPreconditionFailed (412)
|
103
|
+
# - Net::HTTPRequestEntityTooLarge (413)
|
104
|
+
# - Net::HTTPRequestURITooLong (414)
|
105
|
+
# - Net::HTTPUnsupportedMediaType (415)
|
106
|
+
# - Net::HTTPRequestedRangeNotSatisfiable (416)
|
107
|
+
# - Net::HTTPExpectationFailed (417)
|
108
|
+
# - Net::HTTPMisdirectedRequest (421)
|
109
|
+
# - Net::HTTPUnprocessableEntity (422)
|
110
|
+
# - Net::HTTPLocked (423)
|
111
|
+
# - Net::HTTPFailedDependency (424)
|
112
|
+
# - Net::HTTPUpgradeRequired (426)
|
113
|
+
# - Net::HTTPPreconditionRequired (428)
|
114
|
+
# - Net::HTTPTooManyRequests (429)
|
115
|
+
# - Net::HTTPRequestHeaderFieldsTooLarge (431)
|
116
|
+
# - Net::HTTPUnavailableForLegalReasons (451)
|
9
117
|
#
|
10
|
-
#
|
11
|
-
# HTTPResponse subclass. All classes are defined under the Net module.
|
12
|
-
# Indentation indicates inheritance. For a list of the classes see Net::HTTP.
|
118
|
+
# - Net::HTTPServerError:
|
13
119
|
#
|
14
|
-
#
|
15
|
-
#
|
120
|
+
# - Net::HTTPInternalServerError (500)
|
121
|
+
# - Net::HTTPNotImplemented (501)
|
122
|
+
# - Net::HTTPBadGateway (502)
|
123
|
+
# - Net::HTTPServiceUnavailable (503)
|
124
|
+
# - Net::HTTPGatewayTimeOut (504)
|
125
|
+
# - Net::HTTPVersionNotSupported (505)
|
126
|
+
# - Net::HTTPVariantAlsoNegotiates (506)
|
127
|
+
# - Net::HTTPInsufficientStorage (507)
|
128
|
+
# - Net::HTTPLoopDetected (508)
|
129
|
+
# - Net::HTTPNotExtended (510)
|
130
|
+
# - Net::HTTPNetworkAuthenticationRequired (511)
|
16
131
|
#
|
17
|
-
#
|
132
|
+
# There is also the Net::HTTPBadResponse exception which is raised when
|
133
|
+
# there is a protocol error.
|
18
134
|
#
|
19
135
|
class Net::HTTPResponse
|
20
136
|
class << self
|