net-http 0.4.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf933c8a700d19b030c85a6bbd7dc2d9dd5756d50076a13fabbc44284b76af6c
4
- data.tar.gz: 6ed388df8dfe9f603c7a838a274d52940b2494fb35a7fe2eb5514fd0bfbc7e0f
3
+ metadata.gz: 6aa488199745a574db471b279c8cbb4b46cd5dded0308bd5888f0cd9c08d5102
4
+ data.tar.gz: d9804849a6cff66145baf7d6557ca5845ba8777d08acf940e431b11a8c5266d9
5
5
  SHA512:
6
- metadata.gz: cb250a681c61405474f625099b62ff0eaad5334e12ffaca3ce1ad9781bcfc61b289cae035fdbe7850f17255d117b918c2339c6b504b2783899dce64c14fc1291
7
- data.tar.gz: 735ae93466d2c3e019b5c277549751a68708400a7d3ff88a55c1d17d3bfcc6c07d6147023f21cf138812dbca5a1a5b24ed5cd54b3c919a8723f24d88e69b8997
6
+ metadata.gz: d06f7fe540c1fae1b1d73b6b029c6e9b176073cdcf267b5b6b5b98095dd14d9cf53fd406b7cb1d854dbf9e31a8ff52fde927442f6f8250194df4166a00476e59
7
+ data.tar.gz: 3583aa361d6c121814bf3092cd1c314943774009564603452d0b0f17d9f0f35b3a7841ed02806fae131f0c85edc3dbcbe20938f010ac352fc267bfa4b36e0ebe
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ BSDL
2
+ COPYING
3
+ README.md
4
+ lib/
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Net::HTTP provides a rich library which can be used to build HTTP
4
4
  user-agents. For more details about HTTP see
5
- [RFC2616](http://www.ietf.org/rfc/rfc2616.txt).
5
+ [RFC9110 HTTP Semantics](https://www.ietf.org/rfc/rfc9110.html) and
6
+ [RFC9112 HTTP/1.1](https://www.ietf.org/rfc/rfc9112.html).
6
7
 
7
8
  Net::HTTP is designed to work closely with URI. URI::HTTP#host,
8
9
  URI::HTTP#port and URI::HTTP#request_uri are designed to work with
@@ -3,7 +3,7 @@ module Net
3
3
  # Net::HTTP exception class.
4
4
  # You cannot use Net::HTTPExceptions directly; instead, you must use
5
5
  # its subclasses.
6
- module HTTPExceptions
6
+ module HTTPExceptions # :nodoc:
7
7
  def initialize(msg, res) #:nodoc:
8
8
  super msg
9
9
  @response = res
@@ -12,6 +12,7 @@ module Net
12
12
  alias data response #:nodoc: obsolete
13
13
  end
14
14
 
15
+ # :stopdoc:
15
16
  class HTTPError < ProtocolError
16
17
  include HTTPExceptions
17
18
  end
@@ -19,16 +19,13 @@ class Net::HTTPGenericRequest
19
19
 
20
20
  if URI === uri_or_path then
21
21
  raise ArgumentError, "not an HTTP URI" unless URI::HTTP === uri_or_path
22
- hostname = uri_or_path.hostname
22
+ hostname = uri_or_path.host
23
23
  raise ArgumentError, "no host component for URI" unless (hostname && hostname.length > 0)
24
24
  @uri = uri_or_path.dup
25
- host = @uri.hostname.dup
26
- host << ":" << @uri.port.to_s if @uri.port != @uri.default_port
27
25
  @path = uri_or_path.request_uri
28
26
  raise ArgumentError, "no HTTP request path given" unless @path
29
27
  else
30
28
  @uri = nil
31
- host = nil
32
29
  raise ArgumentError, "no HTTP request path given" unless uri_or_path
33
30
  raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
34
31
  @path = uri_or_path.dup
@@ -51,7 +48,7 @@ class Net::HTTPGenericRequest
51
48
  initialize_http_header initheader
52
49
  self['Accept'] ||= '*/*'
53
50
  self['User-Agent'] ||= 'Ruby'
54
- self['Host'] ||= host if host
51
+ self['Host'] ||= @uri.authority if @uri
55
52
  @body = nil
56
53
  @body_stream = nil
57
54
  @body_data = nil
@@ -102,6 +99,31 @@ class Net::HTTPGenericRequest
102
99
  "\#<#{self.class} #{@method}>"
103
100
  end
104
101
 
102
+ # Returns a string representation of the request with the details for pp:
103
+ #
104
+ # require 'pp'
105
+ # post = Net::HTTP::Post.new(uri)
106
+ # post.inspect # => "#<Net::HTTP::Post POST>"
107
+ # post.pretty_inspect
108
+ # # => #<Net::HTTP::Post
109
+ # POST
110
+ # path="/"
111
+ # headers={"accept-encoding" => ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
112
+ # "accept" => ["*/*"],
113
+ # "user-agent" => ["Ruby"],
114
+ # "host" => ["www.ruby-lang.org"]}>
115
+ #
116
+ def pretty_print(q)
117
+ q.object_group(self) {
118
+ q.breakable
119
+ q.text @method
120
+ q.breakable
121
+ q.text "path="; q.pp @path
122
+ q.breakable
123
+ q.text "headers="; q.pp to_hash
124
+ }
125
+ end
126
+
105
127
  ##
106
128
  # Don't automatically decode response content-encoding if the user indicates
107
129
  # they want to handle it.
@@ -220,7 +242,7 @@ class Net::HTTPGenericRequest
220
242
  end
221
243
 
222
244
  if host = self['host']
223
- host.sub!(/:.*/m, '')
245
+ host = URI.parse("//#{host}").host # Remove a port component from the existing Host header
224
246
  elsif host = @uri.host
225
247
  else
226
248
  host = addr
@@ -239,6 +261,8 @@ class Net::HTTPGenericRequest
239
261
 
240
262
  private
241
263
 
264
+ # :stopdoc:
265
+
242
266
  class Chunker #:nodoc:
243
267
  def initialize(sock)
244
268
  @sock = sock
@@ -260,7 +284,6 @@ class Net::HTTPGenericRequest
260
284
  def send_request_with_body(sock, ver, path, body)
261
285
  self.content_length = body.bytesize
262
286
  delete 'Transfer-Encoding'
263
- supply_default_content_type
264
287
  write_header sock, ver, path
265
288
  wait_for_continue sock, ver if sock.continue_timeout
266
289
  sock.write body
@@ -271,7 +294,6 @@ class Net::HTTPGenericRequest
271
294
  raise ArgumentError,
272
295
  "Content-Length not given and Transfer-Encoding is not `chunked'"
273
296
  end
274
- supply_default_content_type
275
297
  write_header sock, ver, path
276
298
  wait_for_continue sock, ver if sock.continue_timeout
277
299
  if chunked?
@@ -373,12 +395,6 @@ class Net::HTTPGenericRequest
373
395
  buf.clear
374
396
  end
375
397
 
376
- def supply_default_content_type
377
- return if content_type()
378
- warn 'net/http: Content-Type did not set; using application/x-www-form-urlencoded', uplevel: 1 if $VERBOSE
379
- set_content_type 'application/x-www-form-urlencoded'
380
- end
381
-
382
398
  ##
383
399
  # Waits up to the continue timeout for a response from the server provided
384
400
  # we're speaking HTTP 1.1 and are expecting a 100-continue response.
@@ -411,4 +427,3 @@ class Net::HTTPGenericRequest
411
427
  end
412
428
 
413
429
  end
414
-
@@ -179,7 +179,9 @@
179
179
  # - #each_value: Passes each string field value to the block.
180
180
  #
181
181
  module Net::HTTPHeader
182
+ # The maximum length of HTTP header keys.
182
183
  MAX_KEY_LENGTH = 1024
184
+ # The maximum length of HTTP header values.
183
185
  MAX_FIELD_LENGTH = 65536
184
186
 
185
187
  def initialize_http_header(initheader) #:nodoc:
@@ -267,6 +269,7 @@ module Net::HTTPHeader
267
269
  end
268
270
  end
269
271
 
272
+ # :stopdoc:
270
273
  private def set_field(key, val)
271
274
  case val
272
275
  when Enumerable
@@ -294,6 +297,7 @@ module Net::HTTPHeader
294
297
  ary.push val
295
298
  end
296
299
  end
300
+ # :startdoc:
297
301
 
298
302
  # Returns the array field value for the given +key+,
299
303
  # or +nil+ if there is no such field;
@@ -490,8 +494,8 @@ module Net::HTTPHeader
490
494
 
491
495
  alias canonical_each each_capitalized
492
496
 
493
- def capitalize(name)
494
- name.to_s.split(/-/).map {|s| s.capitalize }.join('-')
497
+ def capitalize(name) # :nodoc:
498
+ name.to_s.split('-'.freeze).map {|s| s.capitalize }.join('-'.freeze)
495
499
  end
496
500
  private :capitalize
497
501
 
@@ -957,12 +961,12 @@ module Net::HTTPHeader
957
961
  @header['proxy-authorization'] = [basic_encode(account, password)]
958
962
  end
959
963
 
960
- def basic_encode(account, password)
964
+ def basic_encode(account, password) # :nodoc:
961
965
  'Basic ' + ["#{account}:#{password}"].pack('m0')
962
966
  end
963
967
  private :basic_encode
964
968
 
965
- # Returns whether the HTTP session is to be closed.
969
+ # Returns whether the HTTP session is to be closed.
966
970
  def connection_close?
967
971
  token = /(?:\A|,)\s*close\s*(?:\z|,)/i
968
972
  @header['connection']&.grep(token) {return true}
@@ -970,7 +974,7 @@ module Net::HTTPHeader
970
974
  false
971
975
  end
972
976
 
973
- # Returns whether the HTTP session is to be kept alive.
977
+ # Returns whether the HTTP session is to be kept alive.
974
978
  def connection_keep_alive?
975
979
  token = /(?:\A|,)\s*keep-alive\s*(?:\z|,)/i
976
980
  @header['connection']&.grep(token) {return true}
@@ -29,6 +29,7 @@
29
29
  # - Net::HTTP#get: sends +GET+ request, returns response object.
30
30
  #
31
31
  class Net::HTTP::Get < Net::HTTPRequest
32
+ # :stopdoc:
32
33
  METHOD = 'GET'
33
34
  REQUEST_HAS_BODY = false
34
35
  RESPONSE_HAS_BODY = true
@@ -60,6 +61,7 @@ end
60
61
  # - Net::HTTP#head: sends +HEAD+ request, returns response object.
61
62
  #
62
63
  class Net::HTTP::Head < Net::HTTPRequest
64
+ # :stopdoc:
63
65
  METHOD = 'HEAD'
64
66
  REQUEST_HAS_BODY = false
65
67
  RESPONSE_HAS_BODY = false
@@ -95,6 +97,7 @@ end
95
97
  # - Net::HTTP#post: sends +POST+ request, returns response object.
96
98
  #
97
99
  class Net::HTTP::Post < Net::HTTPRequest
100
+ # :stopdoc:
98
101
  METHOD = 'POST'
99
102
  REQUEST_HAS_BODY = true
100
103
  RESPONSE_HAS_BODY = true
@@ -124,7 +127,13 @@ end
124
127
  # - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
125
128
  # - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
126
129
  #
130
+ # Related:
131
+ #
132
+ # - Net::HTTP.put: sends +PUT+ request, returns response object.
133
+ # - Net::HTTP#put: sends +PUT+ request, returns response object.
134
+ #
127
135
  class Net::HTTP::Put < Net::HTTPRequest
136
+ # :stopdoc:
128
137
  METHOD = 'PUT'
129
138
  REQUEST_HAS_BODY = true
130
139
  RESPONSE_HAS_BODY = true
@@ -157,6 +166,7 @@ end
157
166
  # - Net::HTTP#delete: sends +DELETE+ request, returns response object.
158
167
  #
159
168
  class Net::HTTP::Delete < Net::HTTPRequest
169
+ # :stopdoc:
160
170
  METHOD = 'DELETE'
161
171
  REQUEST_HAS_BODY = false
162
172
  RESPONSE_HAS_BODY = true
@@ -188,6 +198,7 @@ end
188
198
  # - Net::HTTP#options: sends +OPTIONS+ request, returns response object.
189
199
  #
190
200
  class Net::HTTP::Options < Net::HTTPRequest
201
+ # :stopdoc:
191
202
  METHOD = 'OPTIONS'
192
203
  REQUEST_HAS_BODY = false
193
204
  RESPONSE_HAS_BODY = true
@@ -219,6 +230,7 @@ end
219
230
  # - Net::HTTP#trace: sends +TRACE+ request, returns response object.
220
231
  #
221
232
  class Net::HTTP::Trace < Net::HTTPRequest
233
+ # :stopdoc:
222
234
  METHOD = 'TRACE'
223
235
  REQUEST_HAS_BODY = false
224
236
  RESPONSE_HAS_BODY = true
@@ -253,6 +265,7 @@ end
253
265
  # - Net::HTTP#patch: sends +PATCH+ request, returns response object.
254
266
  #
255
267
  class Net::HTTP::Patch < Net::HTTPRequest
268
+ # :stopdoc:
256
269
  METHOD = 'PATCH'
257
270
  REQUEST_HAS_BODY = true
258
271
  RESPONSE_HAS_BODY = true
@@ -280,6 +293,7 @@ end
280
293
  # - Net::HTTP#propfind: sends +PROPFIND+ request, returns response object.
281
294
  #
282
295
  class Net::HTTP::Propfind < Net::HTTPRequest
296
+ # :stopdoc:
283
297
  METHOD = 'PROPFIND'
284
298
  REQUEST_HAS_BODY = true
285
299
  RESPONSE_HAS_BODY = true
@@ -303,6 +317,7 @@ end
303
317
  # - Net::HTTP#proppatch: sends +PROPPATCH+ request, returns response object.
304
318
  #
305
319
  class Net::HTTP::Proppatch < Net::HTTPRequest
320
+ # :stopdoc:
306
321
  METHOD = 'PROPPATCH'
307
322
  REQUEST_HAS_BODY = true
308
323
  RESPONSE_HAS_BODY = true
@@ -326,6 +341,7 @@ end
326
341
  # - Net::HTTP#mkcol: sends +MKCOL+ request, returns response object.
327
342
  #
328
343
  class Net::HTTP::Mkcol < Net::HTTPRequest
344
+ # :stopdoc:
329
345
  METHOD = 'MKCOL'
330
346
  REQUEST_HAS_BODY = true
331
347
  RESPONSE_HAS_BODY = true
@@ -349,6 +365,7 @@ end
349
365
  # - Net::HTTP#copy: sends +COPY+ request, returns response object.
350
366
  #
351
367
  class Net::HTTP::Copy < Net::HTTPRequest
368
+ # :stopdoc:
352
369
  METHOD = 'COPY'
353
370
  REQUEST_HAS_BODY = false
354
371
  RESPONSE_HAS_BODY = true
@@ -372,6 +389,7 @@ end
372
389
  # - Net::HTTP#move: sends +MOVE+ request, returns response object.
373
390
  #
374
391
  class Net::HTTP::Move < Net::HTTPRequest
392
+ # :stopdoc:
375
393
  METHOD = 'MOVE'
376
394
  REQUEST_HAS_BODY = false
377
395
  RESPONSE_HAS_BODY = true
@@ -395,6 +413,7 @@ end
395
413
  # - Net::HTTP#lock: sends +LOCK+ request, returns response object.
396
414
  #
397
415
  class Net::HTTP::Lock < Net::HTTPRequest
416
+ # :stopdoc:
398
417
  METHOD = 'LOCK'
399
418
  REQUEST_HAS_BODY = true
400
419
  RESPONSE_HAS_BODY = true
@@ -418,8 +437,8 @@ end
418
437
  # - Net::HTTP#unlock: sends +UNLOCK+ request, returns response object.
419
438
  #
420
439
  class Net::HTTP::Unlock < Net::HTTPRequest
440
+ # :stopdoc:
421
441
  METHOD = 'UNLOCK'
422
442
  REQUEST_HAS_BODY = true
423
443
  RESPONSE_HAS_BODY = true
424
444
  end
425
-
@@ -153,6 +153,7 @@ class Net::HTTPResponse
153
153
  end
154
154
 
155
155
  private
156
+ # :stopdoc:
156
157
 
157
158
  def read_status_line(sock)
158
159
  str = sock.readline
@@ -259,7 +260,7 @@ class Net::HTTPResponse
259
260
  # header.
260
261
  attr_accessor :ignore_eof
261
262
 
262
- def inspect
263
+ def inspect # :nodoc:
263
264
  "#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
264
265
  end
265
266