@@ -106,7 +106,7 @@ class HTTPHeaderSyntaxError < StandardError; end
106
106
# Many code examples here use these example websites:
107
107
#
108
108
# - https://jsonplaceholder.typicode.com.
109
- # - http:example.com.
109
+ # - http:// example.com.
110
110
#
111
111
# Some examples also assume these variables:
112
112
#
@@ -137,7 +137,7 @@ class HTTPHeaderSyntaxError < StandardError; end
137
137
# It consists of some or all of: scheme, hostname, path, query, and fragment;
138
138
# see {URI syntax}[https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax].
139
139
#
140
- # A Ruby {URI::Generic}[] https://docs.ruby-lang.org/en/master/URI/Generic.html] object
140
+ # A Ruby {URI::Generic}[https://docs.ruby-lang.org/en/master/URI/Generic.html] object
141
141
# represents an internet URI.
142
142
# It provides, among others, methods
143
143
# +scheme+, +hostname+, +path+, +query+, and +fragment+.
@@ -204,30 +204,6 @@ class HTTPHeaderSyntaxError < StandardError; end
204
204
# {Request Fields}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields].
205
205
# A host may also accept other custom fields.
206
206
#
207
- # The following example performs a conditional GET using the
208
- # <tt>If-Modified-Since</tt> header:
209
- #
210
- # - If the file +cached_response+ has been modified since the time
211
- # put into the header,
212
- # the return is a \Net::HTTPSuccess object,
213
- # and the file is overwritten with the response body.
214
- # - Otherwise, the return is a \Net::HTTPNotModified object,
215
- # and the file remains unchanged.
216
- #
217
- # The code:
218
- #
219
- # path = 'cached_response'
220
- # File.write(path, '') unless File.exist?(path)
221
- # file = File.stat(path)
222
- # req = Net::HTTP::Get.new(uri)
223
- # req['If-Modified-Since'] = file.mtime.rfc2822
224
- # res = Net::HTTP.start(hostname) do |http|
225
- # http.request(req)
226
- # end
227
- # if res.is_a?(Net::HTTPSuccess)
228
- # File.write(path, res.body)
229
- # end
230
- #
231
207
# == Sessions
232
208
#
233
209
# A _session_ is a connection between a server (host) and a client that:
@@ -465,7 +441,7 @@ class << HTTP
465
441
466
442
# :call-seq:
467
443
# Net::HTTP.get_print(hostname, path, port = 80) -> nil
468
- # Net::HTTP:get_print(uri, headers = {}, port = 80 ) -> nil
444
+ # Net::HTTP:get_print(uri, headers = {}, port = uri.port ) -> nil
469
445
#
470
446
# Like Net::HTTP.get, but writes the returned body to $stdout;
471
447
# returns +nil+.
@@ -480,7 +456,7 @@ def HTTP.get_print(uri_or_host, path_or_headers = nil, port = nil)
480
456
481
457
# :call-seq:
482
458
# Net::HTTP.get(hostname, path, port = 80) -> body
483
- # Net::HTTP:get(uri, headers = {}, port = 80 ) -> body
459
+ # Net::HTTP:get(uri, headers = {}, port = uri.port ) -> body
484
460
#
485
461
# Sends a GET request and returns the \HTTP response body as a string.
486
462
#
@@ -496,33 +472,22 @@ def HTTP.get_print(uri_or_host, path_or_headers = nil, port = nil)
496
472
# "userId": 1,
497
473
# "id": 1,
498
474
# "title": "delectus aut autem",
499
- # "completed":
475
+ # "completed": false
500
476
# }
501
477
#
502
478
# With URI object +uri+ and optional hash argument +headers+:
503
479
#
504
480
# uri = URI('https://jsonplaceholder.typicode.com/todos/1')
505
- # headers = {Accept: 'text/html '}
506
- # puts Net::HTTP.get(uri, headers)
481
+ # headers = {'Content-type' => 'application/json; charset=UTF-8 '}
482
+ # Net::HTTP.get(uri, headers)
507
483
#
508
- # Output:
509
- #
510
- # {
511
- # "userId": 1,
512
- # "id": 1,
513
- # "title": "delectus aut autem",
514
- # "completed": false
515
- # }
516
- #
517
- # In either case, the third argument is an integer port number,
518
- # which defaults to 80.
519
484
def HTTP . get ( uri_or_host , path_or_headers = nil , port = nil )
520
485
get_response ( uri_or_host , path_or_headers , port ) . body
521
486
end
522
487
523
488
# :call-seq:
524
489
# Net::HTTP.get_response(hostname, path, port = 80) -> http_response
525
- # Net::HTTP:get_response(uri, headers = {}, port = 80 ) -> http_response
490
+ # Net::HTTP:get_response(uri, headers = {}, port = uri.port ) -> http_response
526
491
#
527
492
# Like Net::HTTP.get, but returns an Net::HTTPResponse object
528
493
# instead of the body string.
@@ -611,6 +576,9 @@ def HTTP.socket_type #:nodoc: obsolete
611
576
BufferedIO
612
577
end
613
578
579
+ # :call-seq:
580
+ # HTTP.start(address, port, p_addr, p_port, p_user, p_pass) {|http| ... }
581
+ # HTTP.start(address, port=nil, p_addr=:ENV, p_port=nil, p_user=nil, p_pass=nil, opt) {|http| ... }
614
582
# Creates a new \Net::HTTP object,
615
583
# opens a TCP connection and \HTTP session.
616
584
#
0 commit comments