Skip to content

Commit 9a4e2d3

Browse files
committed
Redirection revision
1 parent b098caa commit 9a4e2d3

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

lib/net/http.rb

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,26 @@ class HTTPHeaderSyntaxError < StandardError; end
262262
#
263263
# == Following Redirection
264264
#
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].
266267
#
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:
273271
#
274272
# def fetch(uri, limit = 10)
275273
# # 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
277275
#
278276
# res = Net::HTTP.get_response(URI(uri))
279277
# case res
280-
# when Net::HTTPSuccess then
278+
# when Net::HTTPSuccess # Any success class.
281279
# 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}"
285283
# fetch(location, limit - 1)
286-
# else
284+
# else # Any other class.
287285
# res.value
288286
# end
289287
# end
@@ -320,15 +318,15 @@ class HTTPHeaderSyntaxError < StandardError; end
320318
#
321319
# == HTTPS
322320
#
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=:
324322
#
325323
# Net::HTTP.start(hostname, :use_ssl => true) do |http|
326324
# req = Net::HTTP::Get.new(uri)
327325
# res = http.request(req)
328326
# end
329327
#
330328
# 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
332330
# verification if the URI object has a 'https' URI scheme:
333331
#
334332
# uri # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
@@ -529,18 +527,18 @@ def HTTP.post_form(url, params)
529527
end
530528

531529
#
532-
# HTTP session management
530+
# \HTTP session management
533531
#
534532

535-
# Returns intger +80+, the default port to use for HTTP requests:
533+
# Returns intger +80+, the default port to use for \HTTP requests:
536534
#
537535
# Net::HTTP.default_port # => 80
538536
#
539537
def HTTP.default_port
540538
http_default_port()
541539
end
542540

543-
# Returns integer +80+, the default port to use for HTTP requests:
541+
# Returns integer +80+, the default port to use for \HTTP requests:
544542
#
545543
# Net::HTTP.http_default_port # => 80
546544
#
@@ -673,7 +671,7 @@ class << HTTP
673671
end
674672

675673
# 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).
677675
#
678676
# <b>No Proxy</b>
679677
#
@@ -806,7 +804,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
806804
end
807805

808806
# 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.
810808
# The +address+ should be a DNS hostname or IP address.
811809
def initialize(address, port = nil)
812810
@address = address
@@ -991,20 +989,20 @@ def ipaddr=(addr)
991989
end
992990

993991
# 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
995993
# object cannot open a connection in this many seconds, it raises a
996994
# \Net::OpenTimeout exception. The default value is 60 seconds.
997995
attr_accessor :open_timeout
998996

999997
# Number of seconds to wait for one block to be read (via one read(2)
1000998
# 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,
10021000
# it raises a Net::ReadTimeout exception. The default value is 60 seconds.
10031001
attr_reader :read_timeout
10041002

10051003
# Number of seconds to wait for one block to be written (via one write(2)
10061004
# 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,
10081006
# it raises a \Net::WriteTimeout exception. The default value is 60 seconds.
10091007
# \Net::WriteTimeout is not raised on Windows.
10101008
attr_reader :write_timeout
@@ -1057,7 +1055,7 @@ def write_timeout=(sec)
10571055
@write_timeout = sec
10581056
end
10591057

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
10611059
# receive a response in this many seconds it sends the request body. The
10621060
# default value is +nil+.
10631061
attr_reader :continue_timeout
@@ -1078,7 +1076,7 @@ def continue_timeout=(sec)
10781076
# Content-Length headers. For backwards compatibility, the default is true.
10791077
attr_accessor :ignore_eof
10801078

1081-
# Returns true if the HTTP session has been started.
1079+
# Returns true if the \HTTP session has been started.
10821080
def started?
10831081
@started
10841082
end
@@ -1087,7 +1085,7 @@ def started?
10871085

10881086
attr_accessor :close_on_empty_response
10891087

1090-
# Returns true if SSL/TLS is being used with HTTP.
1088+
# Returns true if SSL/TLS is being used with \HTTP.
10911089
def use_ssl?
10921090
@use_ssl
10931091
end
@@ -1202,10 +1200,10 @@ def peer_cert
12021200
@socket.io.peer_cert
12031201
end
12041202

1205-
# Opens a TCP connection and HTTP session.
1203+
# Opens a TCP connection and \HTTP session.
12061204
#
12071205
# 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
12091207
# after the block has been executed.
12101208
#
12111209
# When called with a block, it returns the return value of the
@@ -1345,7 +1343,7 @@ def on_connect
13451343
end
13461344
private :on_connect
13471345

1348-
# Finishes the HTTP session and closes the TCP connection.
1346+
# Finishes the \HTTP session and closes the TCP connection.
13491347
# Raises IOError if the session has not been started.
13501348
def finish
13511349
raise IOError, 'HTTP session not yet started' unless started?
@@ -1373,7 +1371,7 @@ def do_finish
13731371
@proxy_user = nil
13741372
@proxy_pass = nil
13751373

1376-
# Creates an HTTP proxy class which behaves like \Net::HTTP, but
1374+
# Creates an \HTTP proxy class which behaves like \Net::HTTP, but
13771375
# performs all access via the specified proxy.
13781376
#
13791377
# 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:
17621760
alias put2 request_put #:nodoc: obsolete
17631761

17641762

1765-
# Sends an HTTP request to the HTTP server.
1763+
# Sends an \HTTP request to the \HTTP server.
17661764
# Also sends a DATA string if +data+ is given.
17671765
#
17681766
# Returns a Net::HTTPResponse object.
@@ -1778,7 +1776,7 @@ def send_request(name, path, data = nil, header = nil)
17781776
request r, data
17791777
end
17801778

1781-
# Sends an HTTPRequest object +req+ to the HTTP server.
1779+
# Sends an HTTPRequest object +req+ to the \HTTP server.
17821780
#
17831781
# If +req+ is a Net::HTTP::Post or Net::HTTP::Put request containing
17841782
# data, the data is also sent. Providing data for a Net::HTTP::Head or

0 commit comments

Comments
 (0)