net-http 0.1.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.
@@ -0,0 +1,307 @@
1
+ # frozen_string_literal: true
2
+ # :stopdoc:
3
+ # https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
4
+ class Net::HTTPUnknownResponse < Net::HTTPResponse
5
+ HAS_BODY = true
6
+ EXCEPTION_TYPE = Net::HTTPError
7
+ end
8
+ class Net::HTTPInformation < Net::HTTPResponse # 1xx
9
+ HAS_BODY = false
10
+ EXCEPTION_TYPE = Net::HTTPError
11
+ end
12
+ class Net::HTTPSuccess < Net::HTTPResponse # 2xx
13
+ HAS_BODY = true
14
+ EXCEPTION_TYPE = Net::HTTPError
15
+ end
16
+ class Net::HTTPRedirection < Net::HTTPResponse # 3xx
17
+ HAS_BODY = true
18
+ EXCEPTION_TYPE = Net::HTTPRetriableError
19
+ end
20
+ class Net::HTTPClientError < Net::HTTPResponse # 4xx
21
+ HAS_BODY = true
22
+ EXCEPTION_TYPE = Net::HTTPClientException # for backward compatibility
23
+ end
24
+ class Net::HTTPServerError < Net::HTTPResponse # 5xx
25
+ HAS_BODY = true
26
+ EXCEPTION_TYPE = Net::HTTPFatalError # for backward compatibility
27
+ end
28
+
29
+ class Net::HTTPContinue < Net::HTTPInformation # 100
30
+ HAS_BODY = false
31
+ end
32
+ class Net::HTTPSwitchProtocol < Net::HTTPInformation # 101
33
+ HAS_BODY = false
34
+ end
35
+ class Net::HTTPProcessing < Net::HTTPInformation # 102
36
+ HAS_BODY = false
37
+ end
38
+ class Net::HTTPEarlyHints < Net::HTTPInformation # 103 - RFC 8297
39
+ HAS_BODY = false
40
+ end
41
+
42
+ class Net::HTTPOK < Net::HTTPSuccess # 200
43
+ HAS_BODY = true
44
+ end
45
+ class Net::HTTPCreated < Net::HTTPSuccess # 201
46
+ HAS_BODY = true
47
+ end
48
+ class Net::HTTPAccepted < Net::HTTPSuccess # 202
49
+ HAS_BODY = true
50
+ end
51
+ class Net::HTTPNonAuthoritativeInformation < Net::HTTPSuccess # 203
52
+ HAS_BODY = true
53
+ end
54
+ class Net::HTTPNoContent < Net::HTTPSuccess # 204
55
+ HAS_BODY = false
56
+ end
57
+ class Net::HTTPResetContent < Net::HTTPSuccess # 205
58
+ HAS_BODY = false
59
+ end
60
+ class Net::HTTPPartialContent < Net::HTTPSuccess # 206
61
+ HAS_BODY = true
62
+ end
63
+ class Net::HTTPMultiStatus < Net::HTTPSuccess # 207 - RFC 4918
64
+ HAS_BODY = true
65
+ end
66
+ class Net::HTTPAlreadyReported < Net::HTTPSuccess # 208 - RFC 5842
67
+ HAS_BODY = true
68
+ end
69
+ class Net::HTTPIMUsed < Net::HTTPSuccess # 226 - RFC 3229
70
+ HAS_BODY = true
71
+ end
72
+
73
+ class Net::HTTPMultipleChoices < Net::HTTPRedirection # 300
74
+ HAS_BODY = true
75
+ end
76
+ Net::HTTPMultipleChoice = Net::HTTPMultipleChoices
77
+ class Net::HTTPMovedPermanently < Net::HTTPRedirection # 301
78
+ HAS_BODY = true
79
+ end
80
+ class Net::HTTPFound < Net::HTTPRedirection # 302
81
+ HAS_BODY = true
82
+ end
83
+ Net::HTTPMovedTemporarily = Net::HTTPFound
84
+ class Net::HTTPSeeOther < Net::HTTPRedirection # 303
85
+ HAS_BODY = true
86
+ end
87
+ class Net::HTTPNotModified < Net::HTTPRedirection # 304
88
+ HAS_BODY = false
89
+ end
90
+ class Net::HTTPUseProxy < Net::HTTPRedirection # 305
91
+ HAS_BODY = false
92
+ end
93
+ # 306 Switch Proxy - no longer unused
94
+ class Net::HTTPTemporaryRedirect < Net::HTTPRedirection # 307
95
+ HAS_BODY = true
96
+ end
97
+ class Net::HTTPPermanentRedirect < Net::HTTPRedirection # 308
98
+ HAS_BODY = true
99
+ end
100
+
101
+ class Net::HTTPBadRequest < Net::HTTPClientError # 400
102
+ HAS_BODY = true
103
+ end
104
+ class Net::HTTPUnauthorized < Net::HTTPClientError # 401
105
+ HAS_BODY = true
106
+ end
107
+ class Net::HTTPPaymentRequired < Net::HTTPClientError # 402
108
+ HAS_BODY = true
109
+ end
110
+ class Net::HTTPForbidden < Net::HTTPClientError # 403
111
+ HAS_BODY = true
112
+ end
113
+ class Net::HTTPNotFound < Net::HTTPClientError # 404
114
+ HAS_BODY = true
115
+ end
116
+ class Net::HTTPMethodNotAllowed < Net::HTTPClientError # 405
117
+ HAS_BODY = true
118
+ end
119
+ class Net::HTTPNotAcceptable < Net::HTTPClientError # 406
120
+ HAS_BODY = true
121
+ end
122
+ class Net::HTTPProxyAuthenticationRequired < Net::HTTPClientError # 407
123
+ HAS_BODY = true
124
+ end
125
+ class Net::HTTPRequestTimeout < Net::HTTPClientError # 408
126
+ HAS_BODY = true
127
+ end
128
+ Net::HTTPRequestTimeOut = Net::HTTPRequestTimeout
129
+ class Net::HTTPConflict < Net::HTTPClientError # 409
130
+ HAS_BODY = true
131
+ end
132
+ class Net::HTTPGone < Net::HTTPClientError # 410
133
+ HAS_BODY = true
134
+ end
135
+ class Net::HTTPLengthRequired < Net::HTTPClientError # 411
136
+ HAS_BODY = true
137
+ end
138
+ class Net::HTTPPreconditionFailed < Net::HTTPClientError # 412
139
+ HAS_BODY = true
140
+ end
141
+ class Net::HTTPPayloadTooLarge < Net::HTTPClientError # 413
142
+ HAS_BODY = true
143
+ end
144
+ Net::HTTPRequestEntityTooLarge = Net::HTTPPayloadTooLarge
145
+ class Net::HTTPURITooLong < Net::HTTPClientError # 414
146
+ HAS_BODY = true
147
+ end
148
+ Net::HTTPRequestURITooLong = Net::HTTPURITooLong
149
+ Net::HTTPRequestURITooLarge = Net::HTTPRequestURITooLong
150
+ class Net::HTTPUnsupportedMediaType < Net::HTTPClientError # 415
151
+ HAS_BODY = true
152
+ end
153
+ class Net::HTTPRangeNotSatisfiable < Net::HTTPClientError # 416
154
+ HAS_BODY = true
155
+ end
156
+ Net::HTTPRequestedRangeNotSatisfiable = Net::HTTPRangeNotSatisfiable
157
+ class Net::HTTPExpectationFailed < Net::HTTPClientError # 417
158
+ HAS_BODY = true
159
+ end
160
+ # 418 I'm a teapot - RFC 2324; a joke RFC
161
+ # 420 Enhance Your Calm - Twitter
162
+ class Net::HTTPMisdirectedRequest < Net::HTTPClientError # 421 - RFC 7540
163
+ HAS_BODY = true
164
+ end
165
+ class Net::HTTPUnprocessableEntity < Net::HTTPClientError # 422 - RFC 4918
166
+ HAS_BODY = true
167
+ end
168
+ class Net::HTTPLocked < Net::HTTPClientError # 423 - RFC 4918
169
+ HAS_BODY = true
170
+ end
171
+ class Net::HTTPFailedDependency < Net::HTTPClientError # 424 - RFC 4918
172
+ HAS_BODY = true
173
+ end
174
+ # 425 Unordered Collection - existed only in draft
175
+ class Net::HTTPUpgradeRequired < Net::HTTPClientError # 426 - RFC 2817
176
+ HAS_BODY = true
177
+ end
178
+ class Net::HTTPPreconditionRequired < Net::HTTPClientError # 428 - RFC 6585
179
+ HAS_BODY = true
180
+ end
181
+ class Net::HTTPTooManyRequests < Net::HTTPClientError # 429 - RFC 6585
182
+ HAS_BODY = true
183
+ end
184
+ class Net::HTTPRequestHeaderFieldsTooLarge < Net::HTTPClientError # 431 - RFC 6585
185
+ HAS_BODY = true
186
+ end
187
+ class Net::HTTPUnavailableForLegalReasons < Net::HTTPClientError # 451 - RFC 7725
188
+ HAS_BODY = true
189
+ end
190
+ # 444 No Response - Nginx
191
+ # 449 Retry With - Microsoft
192
+ # 450 Blocked by Windows Parental Controls - Microsoft
193
+ # 499 Client Closed Request - Nginx
194
+
195
+ class Net::HTTPInternalServerError < Net::HTTPServerError # 500
196
+ HAS_BODY = true
197
+ end
198
+ class Net::HTTPNotImplemented < Net::HTTPServerError # 501
199
+ HAS_BODY = true
200
+ end
201
+ class Net::HTTPBadGateway < Net::HTTPServerError # 502
202
+ HAS_BODY = true
203
+ end
204
+ class Net::HTTPServiceUnavailable < Net::HTTPServerError # 503
205
+ HAS_BODY = true
206
+ end
207
+ class Net::HTTPGatewayTimeout < Net::HTTPServerError # 504
208
+ HAS_BODY = true
209
+ end
210
+ Net::HTTPGatewayTimeOut = Net::HTTPGatewayTimeout
211
+ class Net::HTTPVersionNotSupported < Net::HTTPServerError # 505
212
+ HAS_BODY = true
213
+ end
214
+ class Net::HTTPVariantAlsoNegotiates < Net::HTTPServerError # 506
215
+ HAS_BODY = true
216
+ end
217
+ class Net::HTTPInsufficientStorage < Net::HTTPServerError # 507 - RFC 4918
218
+ HAS_BODY = true
219
+ end
220
+ class Net::HTTPLoopDetected < Net::HTTPServerError # 508 - RFC 5842
221
+ HAS_BODY = true
222
+ end
223
+ # 509 Bandwidth Limit Exceeded - Apache bw/limited extension
224
+ class Net::HTTPNotExtended < Net::HTTPServerError # 510 - RFC 2774
225
+ HAS_BODY = true
226
+ end
227
+ class Net::HTTPNetworkAuthenticationRequired < Net::HTTPServerError # 511 - RFC 6585
228
+ HAS_BODY = true
229
+ end
230
+
231
+ class Net::HTTPResponse
232
+ CODE_CLASS_TO_OBJ = {
233
+ '1' => Net::HTTPInformation,
234
+ '2' => Net::HTTPSuccess,
235
+ '3' => Net::HTTPRedirection,
236
+ '4' => Net::HTTPClientError,
237
+ '5' => Net::HTTPServerError
238
+ }
239
+ CODE_TO_OBJ = {
240
+ '100' => Net::HTTPContinue,
241
+ '101' => Net::HTTPSwitchProtocol,
242
+ '102' => Net::HTTPProcessing,
243
+ '103' => Net::HTTPEarlyHints,
244
+
245
+ '200' => Net::HTTPOK,
246
+ '201' => Net::HTTPCreated,
247
+ '202' => Net::HTTPAccepted,
248
+ '203' => Net::HTTPNonAuthoritativeInformation,
249
+ '204' => Net::HTTPNoContent,
250
+ '205' => Net::HTTPResetContent,
251
+ '206' => Net::HTTPPartialContent,
252
+ '207' => Net::HTTPMultiStatus,
253
+ '208' => Net::HTTPAlreadyReported,
254
+ '226' => Net::HTTPIMUsed,
255
+
256
+ '300' => Net::HTTPMultipleChoices,
257
+ '301' => Net::HTTPMovedPermanently,
258
+ '302' => Net::HTTPFound,
259
+ '303' => Net::HTTPSeeOther,
260
+ '304' => Net::HTTPNotModified,
261
+ '305' => Net::HTTPUseProxy,
262
+ '307' => Net::HTTPTemporaryRedirect,
263
+ '308' => Net::HTTPPermanentRedirect,
264
+
265
+ '400' => Net::HTTPBadRequest,
266
+ '401' => Net::HTTPUnauthorized,
267
+ '402' => Net::HTTPPaymentRequired,
268
+ '403' => Net::HTTPForbidden,
269
+ '404' => Net::HTTPNotFound,
270
+ '405' => Net::HTTPMethodNotAllowed,
271
+ '406' => Net::HTTPNotAcceptable,
272
+ '407' => Net::HTTPProxyAuthenticationRequired,
273
+ '408' => Net::HTTPRequestTimeout,
274
+ '409' => Net::HTTPConflict,
275
+ '410' => Net::HTTPGone,
276
+ '411' => Net::HTTPLengthRequired,
277
+ '412' => Net::HTTPPreconditionFailed,
278
+ '413' => Net::HTTPPayloadTooLarge,
279
+ '414' => Net::HTTPURITooLong,
280
+ '415' => Net::HTTPUnsupportedMediaType,
281
+ '416' => Net::HTTPRangeNotSatisfiable,
282
+ '417' => Net::HTTPExpectationFailed,
283
+ '421' => Net::HTTPMisdirectedRequest,
284
+ '422' => Net::HTTPUnprocessableEntity,
285
+ '423' => Net::HTTPLocked,
286
+ '424' => Net::HTTPFailedDependency,
287
+ '426' => Net::HTTPUpgradeRequired,
288
+ '428' => Net::HTTPPreconditionRequired,
289
+ '429' => Net::HTTPTooManyRequests,
290
+ '431' => Net::HTTPRequestHeaderFieldsTooLarge,
291
+ '451' => Net::HTTPUnavailableForLegalReasons,
292
+
293
+ '500' => Net::HTTPInternalServerError,
294
+ '501' => Net::HTTPNotImplemented,
295
+ '502' => Net::HTTPBadGateway,
296
+ '503' => Net::HTTPServiceUnavailable,
297
+ '504' => Net::HTTPGatewayTimeout,
298
+ '505' => Net::HTTPVersionNotSupported,
299
+ '506' => Net::HTTPVariantAlsoNegotiates,
300
+ '507' => Net::HTTPInsufficientStorage,
301
+ '508' => Net::HTTPLoopDetected,
302
+ '510' => Net::HTTPNotExtended,
303
+ '511' => Net::HTTPNetworkAuthenticationRequired,
304
+ }
305
+ end
306
+
307
+ # :startdoc:
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../http'
4
+
5
+ if $0 == __FILE__
6
+ require 'open-uri'
7
+ IO.foreach(__FILE__) do |line|
8
+ puts line
9
+ break if line.start_with?('end')
10
+ end
11
+ puts
12
+ puts "Net::HTTP::STATUS_CODES = {"
13
+ url = "https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv"
14
+ URI(url).read.each_line do |line|
15
+ code, mes, = line.split(',')
16
+ next if ['(Unused)', 'Unassigned', 'Description'].include?(mes)
17
+ puts " #{code} => '#{mes}',"
18
+ end
19
+ puts "}"
20
+ end
21
+
22
+ Net::HTTP::STATUS_CODES = {
23
+ 100 => 'Continue',
24
+ 101 => 'Switching Protocols',
25
+ 102 => 'Processing',
26
+ 103 => 'Early Hints',
27
+ 200 => 'OK',
28
+ 201 => 'Created',
29
+ 202 => 'Accepted',
30
+ 203 => 'Non-Authoritative Information',
31
+ 204 => 'No Content',
32
+ 205 => 'Reset Content',
33
+ 206 => 'Partial Content',
34
+ 207 => 'Multi-Status',
35
+ 208 => 'Already Reported',
36
+ 226 => 'IM Used',
37
+ 300 => 'Multiple Choices',
38
+ 301 => 'Moved Permanently',
39
+ 302 => 'Found',
40
+ 303 => 'See Other',
41
+ 304 => 'Not Modified',
42
+ 305 => 'Use Proxy',
43
+ 307 => 'Temporary Redirect',
44
+ 308 => 'Permanent Redirect',
45
+ 400 => 'Bad Request',
46
+ 401 => 'Unauthorized',
47
+ 402 => 'Payment Required',
48
+ 403 => 'Forbidden',
49
+ 404 => 'Not Found',
50
+ 405 => 'Method Not Allowed',
51
+ 406 => 'Not Acceptable',
52
+ 407 => 'Proxy Authentication Required',
53
+ 408 => 'Request Timeout',
54
+ 409 => 'Conflict',
55
+ 410 => 'Gone',
56
+ 411 => 'Length Required',
57
+ 412 => 'Precondition Failed',
58
+ 413 => 'Payload Too Large',
59
+ 414 => 'URI Too Long',
60
+ 415 => 'Unsupported Media Type',
61
+ 416 => 'Range Not Satisfiable',
62
+ 417 => 'Expectation Failed',
63
+ 421 => 'Misdirected Request',
64
+ 422 => 'Unprocessable Entity',
65
+ 423 => 'Locked',
66
+ 424 => 'Failed Dependency',
67
+ 426 => 'Upgrade Required',
68
+ 428 => 'Precondition Required',
69
+ 429 => 'Too Many Requests',
70
+ 431 => 'Request Header Fields Too Large',
71
+ 451 => 'Unavailable For Legal Reasons',
72
+ 500 => 'Internal Server Error',
73
+ 501 => 'Not Implemented',
74
+ 502 => 'Bad Gateway',
75
+ 503 => 'Service Unavailable',
76
+ 504 => 'Gateway Timeout',
77
+ 505 => 'HTTP Version Not Supported',
78
+ 506 => 'Variant Also Negotiates',
79
+ 507 => 'Insufficient Storage',
80
+ 508 => 'Loop Detected',
81
+ 510 => 'Not Extended',
82
+ 511 => 'Network Authentication Required',
83
+ }
@@ -0,0 +1,5 @@
1
+ module Net
2
+ module Http
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: false
2
+ =begin
3
+
4
+ = net/https -- SSL/TLS enhancement for Net::HTTP.
5
+
6
+ This file has been merged with net/http. There is no longer any need to
7
+ require 'net/https' to use HTTPS.
8
+
9
+ See Net::HTTP for details on how to make HTTPS connections.
10
+
11
+ == Info
12
+ 'OpenSSL for Ruby 2' project
13
+ Copyright (C) 2001 GOTOU Yuuzou <gotoyuzo@notwork.org>
14
+ All rights reserved.
15
+
16
+ == Licence
17
+ This program is licensed under the same licence as Ruby.
18
+ (See the file 'LICENCE'.)
19
+
20
+ =end
21
+
22
+ require_relative 'http'
23
+ require 'openssl'
@@ -0,0 +1,29 @@
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"
5
+ end
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "net-http"
9
+ spec.version = Net::Http::VERSION
10
+ spec.authors = ["NARUSE, Yui"]
11
+ spec.email = ["naruse@airemix.jp"]
12
+
13
+ spec.summary = %q{HTTP client api for Ruby.}
14
+ spec.description = %q{HTTP client api for Ruby.}
15
+ spec.homepage = "https://github.com/ruby/net-http"
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end