@@ -262,28 +262,26 @@ class HTTPHeaderSyntaxError < StandardError; end
262
262
#
263
263
# == Following Redirection
264
264
#
265
- # Each Net::HTTPResponse object belongs to a class for its response code.
265
+ # Each returned response is an instance of a subclass of Net::HTTPResponse.
266
+ # See the {response class hierarchy}[rdoc-ref:Net::HTTPResponse@Response+Subclasses].
266
267
#
267
- # For example, all 2XX responses are instances of a Net::HTTPSuccess
268
- # subclass, a 3XX response is an instance of a Net::HTTPRedirection
269
- # subclass and a 200 response is an instance of the Net::HTTPOK class.
270
- # For details, see HTTPResponse.
271
- #
272
- # Using a case statement you can handle various types of responses properly:
268
+ # In particular, class Net::HTTPRedirection is the parent
269
+ # of all redirection classes.
270
+ # This allows you to craft a case statement to handle redirections properly:
273
271
#
274
272
# def fetch(uri, limit = 10)
275
273
# # You should choose a better exception.
276
- # raise ArgumentError, 'too many HTTP redirects' if limit == 0
274
+ # raise ArgumentError, 'Too many HTTP redirects' if limit == 0
277
275
#
278
276
# res = Net::HTTP.get_response(URI(uri))
279
277
# case res
280
- # when Net::HTTPSuccess then
278
+ # when Net::HTTPSuccess # Any success class.
281
279
# res
282
- # when Net::HTTPRedirection then
283
- # location = res['location ']
284
- # warn "redirected to #{location}"
280
+ # when Net::HTTPRedirection # Any redirection class.
281
+ # location = res['Location ']
282
+ # warn "Redirected to #{location}"
285
283
# fetch(location, limit - 1)
286
- # else
284
+ # else # Any other class.
287
285
# res.value
288
286
# end
289
287
# end
@@ -320,15 +318,15 @@ class HTTPHeaderSyntaxError < StandardError; end
320
318
#
321
319
# == HTTPS
322
320
#
323
- # HTTPS is enabled for an HTTP connection by Net::HTTP#use_ssl=:
321
+ # HTTPS is enabled for an \ HTTP connection by Net::HTTP#use_ssl=:
324
322
#
325
323
# Net::HTTP.start(hostname, :use_ssl => true) do |http|
326
324
# req = Net::HTTP::Get.new(uri)
327
325
# res = http.request(req)
328
326
# end
329
327
#
330
328
# Or if you simply want to make a GET request, you may pass in a URI
331
- # object that has an HTTPS URL. \Net::HTTP automatically turns on TLS
329
+ # object that has an \ HTTPS URL. \Net::HTTP automatically turns on TLS
332
330
# verification if the URI object has a 'https' URI scheme:
333
331
#
334
332
# uri # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
@@ -529,18 +527,18 @@ def HTTP.post_form(url, params)
529
527
end
530
528
531
529
#
532
- # HTTP session management
530
+ # \ HTTP session management
533
531
#
534
532
535
- # Returns intger +80+, the default port to use for HTTP requests:
533
+ # Returns intger +80+, the default port to use for \ HTTP requests:
536
534
#
537
535
# Net::HTTP.default_port # => 80
538
536
#
539
537
def HTTP . default_port
540
538
http_default_port ( )
541
539
end
542
540
543
- # Returns integer +80+, the default port to use for HTTP requests:
541
+ # Returns integer +80+, the default port to use for \ HTTP requests:
544
542
#
545
543
# Net::HTTP.http_default_port # => 80
546
544
#
@@ -673,7 +671,7 @@ class << HTTP
673
671
end
674
672
675
673
# Returns a new \Net::HTTP object +http+
676
- # (but does not open a TCP connection or HTTP session).
674
+ # (but does not open a TCP connection or \ HTTP session).
677
675
#
678
676
# <b>No Proxy</b>
679
677
#
@@ -806,7 +804,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
806
804
end
807
805
808
806
# Creates a new \Net::HTTP object for the specified server address,
809
- # without opening the TCP connection or initializing the HTTP session.
807
+ # without opening the TCP connection or initializing the \ HTTP session.
810
808
# The +address+ should be a DNS hostname or IP address.
811
809
def initialize ( address , port = nil )
812
810
@address = address
@@ -991,20 +989,20 @@ def ipaddr=(addr)
991
989
end
992
990
993
991
# Number of seconds to wait for the connection to open. Any number
994
- # may be used, including Floats for fractional seconds. If the HTTP
992
+ # may be used, including Floats for fractional seconds. If the \ HTTP
995
993
# object cannot open a connection in this many seconds, it raises a
996
994
# \Net::OpenTimeout exception. The default value is 60 seconds.
997
995
attr_accessor :open_timeout
998
996
999
997
# Number of seconds to wait for one block to be read (via one read(2)
1000
998
# call). Any number may be used, including Floats for fractional
1001
- # seconds. If the HTTP object cannot read data in this many seconds,
999
+ # seconds. If the \ HTTP object cannot read data in this many seconds,
1002
1000
# it raises a Net::ReadTimeout exception. The default value is 60 seconds.
1003
1001
attr_reader :read_timeout
1004
1002
1005
1003
# Number of seconds to wait for one block to be written (via one write(2)
1006
1004
# call). Any number may be used, including Floats for fractional
1007
- # seconds. If the HTTP object cannot write data in this many seconds,
1005
+ # seconds. If the \ HTTP object cannot write data in this many seconds,
1008
1006
# it raises a \Net::WriteTimeout exception. The default value is 60 seconds.
1009
1007
# \Net::WriteTimeout is not raised on Windows.
1010
1008
attr_reader :write_timeout
@@ -1057,7 +1055,7 @@ def write_timeout=(sec)
1057
1055
@write_timeout = sec
1058
1056
end
1059
1057
1060
- # Seconds to wait for 100 Continue response. If the HTTP object does not
1058
+ # Seconds to wait for 100 Continue response. If the \ HTTP object does not
1061
1059
# receive a response in this many seconds it sends the request body. The
1062
1060
# default value is +nil+.
1063
1061
attr_reader :continue_timeout
@@ -1078,7 +1076,7 @@ def continue_timeout=(sec)
1078
1076
# Content-Length headers. For backwards compatibility, the default is true.
1079
1077
attr_accessor :ignore_eof
1080
1078
1081
- # Returns true if the HTTP session has been started.
1079
+ # Returns true if the \ HTTP session has been started.
1082
1080
def started?
1083
1081
@started
1084
1082
end
@@ -1087,7 +1085,7 @@ def started?
1087
1085
1088
1086
attr_accessor :close_on_empty_response
1089
1087
1090
- # Returns true if SSL/TLS is being used with HTTP.
1088
+ # Returns true if SSL/TLS is being used with \ HTTP.
1091
1089
def use_ssl?
1092
1090
@use_ssl
1093
1091
end
@@ -1202,10 +1200,10 @@ def peer_cert
1202
1200
@socket . io . peer_cert
1203
1201
end
1204
1202
1205
- # Opens a TCP connection and HTTP session.
1203
+ # Opens a TCP connection and \ HTTP session.
1206
1204
#
1207
1205
# When this method is called with a block, it passes the \Net::HTTP
1208
- # object to the block, and closes the TCP connection and HTTP session
1206
+ # object to the block, and closes the TCP connection and \ HTTP session
1209
1207
# after the block has been executed.
1210
1208
#
1211
1209
# When called with a block, it returns the return value of the
@@ -1345,7 +1343,7 @@ def on_connect
1345
1343
end
1346
1344
private :on_connect
1347
1345
1348
- # Finishes the HTTP session and closes the TCP connection.
1346
+ # Finishes the \ HTTP session and closes the TCP connection.
1349
1347
# Raises IOError if the session has not been started.
1350
1348
def finish
1351
1349
raise IOError , 'HTTP session not yet started' unless started?
@@ -1373,7 +1371,7 @@ def do_finish
1373
1371
@proxy_user = nil
1374
1372
@proxy_pass = nil
1375
1373
1376
- # Creates an HTTP proxy class which behaves like \Net::HTTP, but
1374
+ # Creates an \ HTTP proxy class which behaves like \Net::HTTP, but
1377
1375
# performs all access via the specified proxy.
1378
1376
#
1379
1377
# This class is obsolete. You may pass these same parameters directly to
@@ -1762,7 +1760,7 @@ def request_put(path, data, initheader = nil, &block) #:nodoc:
1762
1760
alias put2 request_put #:nodoc: obsolete
1763
1761
1764
1762
1765
- # Sends an HTTP request to the HTTP server.
1763
+ # Sends an \ HTTP request to the \ HTTP server.
1766
1764
# Also sends a DATA string if +data+ is given.
1767
1765
#
1768
1766
# Returns a Net::HTTPResponse object.
@@ -1778,7 +1776,7 @@ def send_request(name, path, data = nil, header = nil)
1778
1776
request r , data
1779
1777
end
1780
1778
1781
- # Sends an HTTPRequest object +req+ to the HTTP server.
1779
+ # Sends an HTTPRequest object +req+ to the \ HTTP server.
1782
1780
#
1783
1781
# If +req+ is a Net::HTTP::Post or Net::HTTP::Put request containing
1784
1782
# data, the data is also sent. Providing data for a Net::HTTP::Head or
0 commit comments