@@ -1058,6 +1058,7 @@ def read_timeout=(sec)
1058
1058
# EOF
1059
1059
# headers = {'content-type': 'application/json'}
1060
1060
# http = Net::HTTP.new(hostname)
1061
+ # http.write_timeout # => 60
1061
1062
# http.post(_uri.path, data, headers)
1062
1063
# # => #<Net::HTTPCreated 201 Created readbody=true>
1063
1064
# http.write_timeout = 0
@@ -1068,12 +1069,15 @@ def write_timeout=(sec)
1068
1069
@write_timeout = sec
1069
1070
end
1070
1071
1071
- # Seconds to wait for 100 Continue response. If the \HTTP object does not
1072
- # receive a response in this many seconds it sends the request body. The
1073
- # default value is +nil+.
1072
+ # Returns the continue timeout value.
1073
+ # See Net::HTTP.continue_timeout=.
1074
+ #
1074
1075
attr_reader :continue_timeout
1075
1076
1076
- # Setter for the continue_timeout attribute.
1077
+ # Sets the continue timeout value,
1078
+ # which is the number of seconds to wait for an expected 100 Continue response.
1079
+ # If the \HTTP object does not receive a response in this many seconds
1080
+ # it sends the request body.
1077
1081
def continue_timeout = ( sec )
1078
1082
@socket . continue_timeout = sec if @socket
1079
1083
@continue_timeout = sec
@@ -1089,7 +1093,20 @@ def continue_timeout=(sec)
1089
1093
# Content-Length headers. For backwards compatibility, the default is true.
1090
1094
attr_accessor :ignore_eof
1091
1095
1092
- # Returns true if the \HTTP session has been started.
1096
+ # Returns +true+ if the \HTTP session has been started:
1097
+ #
1098
+ # http = Net::HTTP.new(hostname)
1099
+ # http.started? # => false
1100
+ # http.start
1101
+ # http.started? # => true
1102
+ # http.finish # => nil
1103
+ # http.started? # => false
1104
+ #
1105
+ # Net::HTTP.start(hostname) do |http|
1106
+ # http.started?
1107
+ # end # => true
1108
+ # http.started? # => false
1109
+ #
1093
1110
def started?
1094
1111
@started
1095
1112
end
@@ -1098,15 +1115,18 @@ def started?
1098
1115
1099
1116
attr_accessor :close_on_empty_response
1100
1117
1101
- # Returns true if SSL/TLS is being used with \HTTP.
1118
+ # Returns +true+ if +self+ uses SSL, +false+ otherwise.
1119
+ # See Net::HTTP#use_ssl=.
1102
1120
def use_ssl?
1103
1121
@use_ssl
1104
1122
end
1105
1123
1106
- # Turn on/off SSL.
1107
- # This flag must be set before starting session.
1108
- # If you change use_ssl value after session started,
1109
- # IOError is raised.
1124
+ # Sets whether a new session is to use
1125
+ # {Transport Layer Security}[https://en.wikipedia.org/wiki/Transport_Layer_Security]:
1126
+ #
1127
+ # Raises IOError if attempting to change during a session.
1128
+ #
1129
+ # Raises OpenSSL::SSL::SSLError if the port is not an HTTPS port.
1110
1130
def use_ssl = ( flag )
1111
1131
flag = flag ? true : false
1112
1132
if started? and @use_ssl != flag
@@ -1205,22 +1225,35 @@ def use_ssl=(flag)
1205
1225
# See OpenSSL::SSL::SSLContext#verify_hostname=
1206
1226
attr_accessor :verify_hostname
1207
1227
1208
- # Returns the X.509 certificates the server presented.
1228
+ # The X509 certificate chain (an array of strings) for the session's socket peer,
1229
+ # or +nil+ if none.
1209
1230
def peer_cert
1210
1231
if not use_ssl? or not @socket
1211
1232
return nil
1212
1233
end
1213
1234
@socket . io . peer_cert
1214
1235
end
1215
1236
1216
- # Opens a TCP connection and \HTTP session.
1237
+ # Starts an \HTTP session.
1217
1238
#
1218
- # When this method is called with a block, it passes the \Net::HTTP
1219
- # object to the block, and closes the TCP connection and \HTTP session
1220
- # after the block has been executed.
1239
+ # Without a block, returns +self+:
1221
1240
#
1222
- # When called with a block, it returns the return value of the
1223
- # block; otherwise, it returns self.
1241
+ # http = Net::HTTP.new(hostname)
1242
+ # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
1243
+ # http.start
1244
+ # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=true>
1245
+ # http.started? # => true
1246
+ # http.finish
1247
+ #
1248
+ # With a block, calls the block with +self+,
1249
+ # finishes the session when the block exits,
1250
+ # and returns the block's value:
1251
+ #
1252
+ # http.start do |http|
1253
+ # http
1254
+ # end
1255
+ # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
1256
+ # http.started? # => false
1224
1257
#
1225
1258
def start # :yield: http
1226
1259
raise IOError , 'HTTP session already opened' if @started
@@ -1356,8 +1389,15 @@ def on_connect
1356
1389
end
1357
1390
private :on_connect
1358
1391
1359
- # Finishes the \HTTP session and closes the TCP connection.
1360
- # Raises IOError if the session has not been started.
1392
+ # Finishes the \HTTP session:
1393
+ #
1394
+ # http = Net::HTTP.new(hostname)
1395
+ # http.start
1396
+ # http.started? # => true
1397
+ # http.finish # => nil
1398
+ # http.started? # => false
1399
+ #
1400
+ # Raises IOError if not in a session.
1361
1401
def finish
1362
1402
raise IOError , 'HTTP session not yet started' unless started?
1363
1403
do_finish
0 commit comments