Skip to content

Commit e337b85

Browse files
committed
merge revision(s) 1b4c149,62e2b61607c04ff0d2543f0515b2171a24e66b4e,fd0a5659cadb49f1640b20896cd750decdbbd701,c8c3431b0a5995d58f97c511ffa0a39e0f19c75e,755c379d877c66916d20840f07738d6050da3ca2,030f39822ac9d6d7dcdb639e099b320d3517c19c,2f19c5b7e080f75c3373c5b1671b4d4cfab6d334:
[ruby/net-http] [DOC] What's Here for Net:HTTP (ruby/net-http#128) ruby/net-http@39e70f0f9b --- lib/net/http.rb | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 267 insertions(+), 2 deletions(-) Replaced non-ascii charactor. It fails version detection at `net-http.gemspec`. ># Returns the X509 certificate chain for the session<E2><80><99>s socket peer. --- lib/net/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) [ruby/net-http] Test building packages Also revert commit ruby/net-http@d22ca54904de "Replaced non-ascii charactor. It fails version detection at `net-http.gemspec`." ruby/net-http@fbeb247d93 --- lib/net/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) [ruby/net-http] Read in binary mode to get rid of invalid byte sequence ruby/net-http@38de3d17a7 --- lib/net/http/net-http.gemspec | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) [ruby/net-http] Exclude git related files ruby/net-http@2767df580d --- lib/net/http/net-http.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) [ruby/net-http] Re-apply ruby/net-http@d22ca54904de after testing ruby/net-http@7ac7401a9c --- lib/net/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) [ruby/net-http] Enhanced RDoc for Net::HTTP (ruby/net-http#130) ruby/net-http@698e18cfc1 --- lib/net/http/response.rb | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-)
1 parent 0869dc5 commit e337b85

File tree

4 files changed

+313
-24
lines changed

4 files changed

+313
-24
lines changed

lib/net/http.rb

Lines changed: 267 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class HTTPHeaderSyntaxError < StandardError; end
173173
# {Request Fields}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields].
174174
# A host may also accept other custom fields.
175175
#
176-
# == Sessions
176+
# == \HTTP Sessions
177177
#
178178
# A _session_ is a connection between a server (host) and a client that:
179179
#
@@ -454,6 +454,271 @@ class HTTPHeaderSyntaxError < StandardError; end
454454
# - Any other value:
455455
# leaves the body and header unchanged.
456456
#
457+
# == What's Here
458+
#
459+
# This is a categorized summary of methods and attributes.
460+
#
461+
# === \Net::HTTP Objects
462+
#
463+
# - {::new}[rdoc-ref:Net::HTTP.new]:
464+
# Creates a new instance.
465+
# - {#inspect}[rdoc-ref:Net::HTTP#inspect]:
466+
# Returns a string representation of +self+.
467+
#
468+
# === Sessions
469+
#
470+
# - {::start}[rdoc-ref:Net::HTTP.start]:
471+
# Begins a new session in a new \Net::HTTP object.
472+
# - {#started?}[rdoc-ref:Net::HTTP#started?]
473+
# (aliased as {#active?}[rdoc-ref:Net::HTTP#active?]):
474+
# Returns whether in a session.
475+
# - {#finish}[rdoc-ref:Net::HTTP#finish]:
476+
# Ends an active session.
477+
# - {#start}[rdoc-ref:Net::HTTP#start]:
478+
# Begins a new session in an existing \Net::HTTP object (+self+).
479+
#
480+
# === Connections
481+
#
482+
# - {:continue_timeout}[rdoc-ref:Net::HTTP#continue_timeout]:
483+
# Returns the continue timeout.
484+
# - {#continue_timeout=}[rdoc-ref:Net::HTTP#continue_timeout=]:
485+
# Sets the continue timeout seconds.
486+
# - {:keep_alive_timeout}[rdoc-ref:Net::HTTP#keep_alive_timeout]:
487+
# Returns the keep-alive timeout.
488+
# - {:keep_alive_timeout=}[rdoc-ref:Net::HTTP#keep_alive_timeout=]:
489+
# Sets the keep-alive timeout.
490+
# - {:max_retries}[rdoc-ref:Net::HTTP#max_retries]:
491+
# Returns the maximum retries.
492+
# - {#max_retries=}[rdoc-ref:Net::HTTP#max_retries=]:
493+
# Sets the maximum retries.
494+
# - {:open_timeout}[rdoc-ref:Net::HTTP#open_timeout]:
495+
# Returns the open timeout.
496+
# - {:open_timeout=}[rdoc-ref:Net::HTTP#open_timeout=]:
497+
# Sets the open timeout.
498+
# - {:read_timeout}[rdoc-ref:Net::HTTP#read_timeout]:
499+
# Returns the open timeout.
500+
# - {:read_timeout=}[rdoc-ref:Net::HTTP#read_timeout=]:
501+
# Sets the read timeout.
502+
# - {:ssl_timeout}[rdoc-ref:Net::HTTP#ssl_timeout]:
503+
# Returns the ssl timeout.
504+
# - {:ssl_timeout=}[rdoc-ref:Net::HTTP#ssl_timeout=]:
505+
# Sets the ssl timeout.
506+
# - {:write_timeout}[rdoc-ref:Net::HTTP#write_timeout]:
507+
# Returns the write timeout.
508+
# - {write_timeout=}[rdoc-ref:Net::HTTP#write_timeout=]:
509+
# Sets the write timeout.
510+
#
511+
# === Requests
512+
#
513+
# - {::get}[rdoc-ref:Net::HTTP.get]:
514+
# Sends a GET request and returns the string response body.
515+
# - {::get_print}[rdoc-ref:Net::HTTP.get_print]:
516+
# Sends a GET request and write the string response body to $stdout.
517+
# - {::get_response}[rdoc-ref:Net::HTTP.get_response]:
518+
# Sends a GET request and returns a response object.
519+
# - {::post_form}[rdoc-ref:Net::HTTP.post_form]:
520+
# Sends a POST request with form data and returns a response object.
521+
# - {::post}[rdoc-ref:Net::HTTP.post]:
522+
# Sends a POST request with data and returns a response object.
523+
# - {#copy}[rdoc-ref:Net::HTTP#copy]:
524+
# Sends a COPY request and returns a response object.
525+
# - {#delete}[rdoc-ref:Net::HTTP#delete]:
526+
# Sends a DELETE request and returns a response object.
527+
# - {#get}[rdoc-ref:Net::HTTP#get]:
528+
# Sends a GET request and returns a response object.
529+
# - {#head}[rdoc-ref:Net::HTTP#head]:
530+
# Sends a HEAD request and returns a response object.
531+
# - {#lock}[rdoc-ref:Net::HTTP#lock]:
532+
# Sends a LOCK request and returns a response object.
533+
# - {#mkcol}[rdoc-ref:Net::HTTP#mkcol]:
534+
# Sends a MKCOL request and returns a response object.
535+
# - {#move}[rdoc-ref:Net::HTTP#move]:
536+
# Sends a MOVE request and returns a response object.
537+
# - {#options}[rdoc-ref:Net::HTTP#options]:
538+
# Sends a OPTIONS request and returns a response object.
539+
# - {#patch}[rdoc-ref:Net::HTTP#patch]:
540+
# Sends a PATCH request and returns a response object.
541+
# - {#post}[rdoc-ref:Net::HTTP#post]:
542+
# Sends a POST request and returns a response object.
543+
# - {#propfind}[rdoc-ref:Net::HTTP#propfind]:
544+
# Sends a PROPFIND request and returns a response object.
545+
# - {#proppatch}[rdoc-ref:Net::HTTP#proppatch]:
546+
# Sends a PROPPATCH request and returns a response object.
547+
# - {#put}[rdoc-ref:Net::HTTP#put]:
548+
# Sends a PUT request and returns a response object.
549+
# - {#request}[rdoc-ref:Net::HTTP#request]:
550+
# Sends a request and returns a response object.
551+
# - {#request_get}[rdoc-ref:Net::HTTP#request_get]
552+
# (aliased as {#get2}[rdoc-ref:Net::HTTP#get2]):
553+
# Sends a GET request and forms a response object;
554+
# if a block given, calls the block with the object,
555+
# otherwise returns the object.
556+
# - {#request_head}[rdoc-ref:Net::HTTP#request_head]
557+
# (aliased as {#head2}[rdoc-ref:Net::HTTP#head2]):
558+
# Sends a HEAD request and forms a response object;
559+
# if a block given, calls the block with the object,
560+
# otherwise returns the object.
561+
# - {#request_post}[rdoc-ref:Net::HTTP#request_post]
562+
# (aliased as {#post2}[rdoc-ref:Net::HTTP#post2]):
563+
# Sends a POST request and forms a response object;
564+
# if a block given, calls the block with the object,
565+
# otherwise returns the object.
566+
# - {#send_request}[rdoc-ref:Net::HTTP#send_request]:
567+
# Sends a request and returns a response object.
568+
# - {#trace}[rdoc-ref:Net::HTTP#trace]:
569+
# Sends a TRACE request and returns a response object.
570+
# - {#unlock}[rdoc-ref:Net::HTTP#unlock]:
571+
# Sends an UNLOCK request and returns a response object.
572+
#
573+
# === Responses
574+
#
575+
# - {:close_on_empty_response}[rdoc-ref:Net::HTTP#close_on_empty_response]:
576+
# Returns whether to close connection on empty response.
577+
# - {:close_on_empty_response=}[rdoc-ref:Net::HTTP#close_on_empty_response=]:
578+
# Sets whether to close connection on empty response.
579+
# - {:ignore_eof}[rdoc-ref:Net::HTTP#ignore_eof]:
580+
# Returns whether to ignore end-of-file when reading a response body
581+
# with <tt>Content-Length</tt> headers.
582+
# - {:ignore_eof=}[rdoc-ref:Net::HTTP#ignore_eof=]:
583+
# Sets whether to ignore end-of-file when reading a response body
584+
# with <tt>Content-Length</tt> headers.
585+
# - {:response_body_encoding}[rdoc-ref:Net::HTTP#response_body_encoding]:
586+
# Returns the encoding to use for the response body.
587+
# - {#response_body_encoding=}[rdoc-ref:Net::HTTP#response_body_encoding=]:
588+
# Sets the response body encoding.
589+
#
590+
# === Proxies
591+
#
592+
# - {:proxy_address}[rdoc-ref:Net::HTTP#proxy_address]:
593+
# Returns the proxy address.
594+
# - {:proxy_address=}[rdoc-ref:Net::HTTP#proxy_address=]:
595+
# Sets the proxy address.
596+
# - {::proxy_class?}[rdoc-ref:Net::HTTP.proxy_class?]:
597+
# Returns whether +self+ is a proxy class.
598+
# - {#proxy?}[rdoc-ref:Net::HTTP#proxy?]:
599+
# Returns whether +self+ has a proxy.
600+
# - {#proxy_address}[rdoc-ref:Net::HTTP#proxy_address]
601+
# (aliased as {#proxyaddr}[rdoc-ref:Net::HTTP#proxyaddr]):
602+
# Returns the proxy address.
603+
# - {#proxy_from_env?}[rdoc-ref:Net::HTTP#proxy_from_env?]:
604+
# Returns whether the proxy is taken from an environment variable.
605+
# - {:proxy_from_env=}[rdoc-ref:Net::HTTP#proxy_from_env=]:
606+
# Sets whether the proxy is to be taken from an environment variable.
607+
# - {:proxy_pass}[rdoc-ref:Net::HTTP#proxy_pass]:
608+
# Returns the proxy password.
609+
# - {:proxy_pass=}[rdoc-ref:Net::HTTP#proxy_pass=]:
610+
# Sets the proxy password.
611+
# - {:proxy_port}[rdoc-ref:Net::HTTP#proxy_port]:
612+
# Returns the proxy port.
613+
# - {:proxy_port=}[rdoc-ref:Net::HTTP#proxy_port=]:
614+
# Sets the proxy port.
615+
# - {#proxy_user}[rdoc-ref:Net::HTTP#proxy_user]:
616+
# Returns the proxy user name.
617+
# - {:proxy_user=}[rdoc-ref:Net::HTTP#proxy_user=]:
618+
# Sets the proxy user.
619+
#
620+
# === Security
621+
#
622+
# - {:ca_file}[rdoc-ref:Net::HTTP#ca_file]:
623+
# Returns the path to a CA certification file.
624+
# - {:ca_file=}[rdoc-ref:Net::HTTP#ca_file=]:
625+
# Sets the path to a CA certification file.
626+
# - {:ca_path}[rdoc-ref:Net::HTTP#ca_path]:
627+
# Returns the path of to CA directory containing certification files.
628+
# - {:ca_path=}[rdoc-ref:Net::HTTP#ca_path=]:
629+
# Sets the path of to CA directory containing certification files.
630+
# - {:cert}[rdoc-ref:Net::HTTP#cert]:
631+
# Returns the OpenSSL::X509::Certificate object to be used for client certification.
632+
# - {:cert=}[rdoc-ref:Net::HTTP#cert=]:
633+
# Sets the OpenSSL::X509::Certificate object to be used for client certification.
634+
# - {:cert_store}[rdoc-ref:Net::HTTP#cert_store]:
635+
# Returns the X509::Store to be used for verifying peer certificate.
636+
# - {:cert_store=}[rdoc-ref:Net::HTTP#cert_store=]:
637+
# Sets the X509::Store to be used for verifying peer certificate.
638+
# - {:ciphers}[rdoc-ref:Net::HTTP#ciphers]:
639+
# Returns the available SSL ciphers.
640+
# - {:ciphers=}[rdoc-ref:Net::HTTP#ciphers=]:
641+
# Sets the available SSL ciphers.
642+
# - {:extra_chain_cert}[rdoc-ref:Net::HTTP#extra_chain_cert]:
643+
# Returns the extra X509 certificates to be added to the certificate chain.
644+
# - {:extra_chain_cert=}[rdoc-ref:Net::HTTP#extra_chain_cert=]:
645+
# Sets the extra X509 certificates to be added to the certificate chain.
646+
# - {:key}[rdoc-ref:Net::HTTP#key]:
647+
# Returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
648+
# - {:key=}[rdoc-ref:Net::HTTP#key=]:
649+
# Sets the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
650+
# - {:max_version}[rdoc-ref:Net::HTTP#max_version]:
651+
# Returns the maximum SSL version.
652+
# - {:max_version=}[rdoc-ref:Net::HTTP#max_version=]:
653+
# Sets the maximum SSL version.
654+
# - {:min_version}[rdoc-ref:Net::HTTP#min_version]:
655+
# Returns the minimum SSL version.
656+
# - {:min_version=}[rdoc-ref:Net::HTTP#min_version=]:
657+
# Sets the minimum SSL version.
658+
# - {#peer_cert}[rdoc-ref:Net::HTTP#peer_cert]:
659+
# Returns the X509 certificate chain for the session's socket peer.
660+
# - {:ssl_version}[rdoc-ref:Net::HTTP#ssl_version]:
661+
# Returns the SSL version.
662+
# - {:ssl_version=}[rdoc-ref:Net::HTTP#ssl_version=]:
663+
# Sets the SSL version.
664+
# - {#use_ssl=}[rdoc-ref:Net::HTTP#use_ssl=]:
665+
# Sets whether a new session is to use Transport Layer Security.
666+
# - {#use_ssl?}[rdoc-ref:Net::HTTP#use_ssl?]:
667+
# Returns whether +self+ uses SSL.
668+
# - {:verify_callback}[rdoc-ref:Net::HTTP#verify_callback]:
669+
# Returns the callback for the server certification verification.
670+
# - {:verify_callback=}[rdoc-ref:Net::HTTP#verify_callback=]:
671+
# Sets the callback for the server certification verification.
672+
# - {:verify_depth}[rdoc-ref:Net::HTTP#verify_depth]:
673+
# Returns the maximum depth for the certificate chain verification.
674+
# - {:verify_depth=}[rdoc-ref:Net::HTTP#verify_depth=]:
675+
# Sets the maximum depth for the certificate chain verification.
676+
# - {:verify_hostname}[rdoc-ref:Net::HTTP#verify_hostname]:
677+
# Returns the flags for server the certification verification at the beginning of the SSL/TLS session.
678+
# - {:verify_hostname=}[rdoc-ref:Net::HTTP#verify_hostname=]:
679+
# Sets he flags for server the certification verification at the beginning of the SSL/TLS session.
680+
# - {:verify_mode}[rdoc-ref:Net::HTTP#verify_mode]:
681+
# Returns the flags for server the certification verification at the beginning of the SSL/TLS session.
682+
# - {:verify_mode=}[rdoc-ref:Net::HTTP#verify_mode=]:
683+
# Sets the flags for server the certification verification at the beginning of the SSL/TLS session.
684+
#
685+
# === Addresses and Ports
686+
#
687+
# - {:address}[rdoc-ref:Net::HTTP#address]:
688+
# Returns the string host name or host IP.
689+
# - {::default_port}[rdoc-ref:Net::HTTP.default_port]:
690+
# Returns integer 80, the default port to use for HTTP requests.
691+
# - {::http_default_port}[rdoc-ref:Net::HTTP.http_default_port]:
692+
# Returns integer 80, the default port to use for HTTP requests.
693+
# - {::https_default_port}[rdoc-ref:Net::HTTP.https_default_port]:
694+
# Returns integer 443, the default port to use for HTTPS requests.
695+
# - {#ipaddr}[rdoc-ref:Net::HTTP#ipaddr]:
696+
# Returns the IP address for the connection.
697+
# - {#ipaddr=}[rdoc-ref:Net::HTTP#ipaddr=]:
698+
# Sets the IP address for the connection.
699+
# - {:local_host}[rdoc-ref:Net::HTTP#local_host]:
700+
# Returns the string local host used to establish the connection.
701+
# - {:local_host=}[rdoc-ref:Net::HTTP#local_host=]:
702+
# Sets the string local host used to establish the connection.
703+
# - {:local_port}[rdoc-ref:Net::HTTP#local_port]:
704+
# Returns the integer local port used to establish the connection.
705+
# - {:local_port=}[rdoc-ref:Net::HTTP#local_port=]:
706+
# Sets the integer local port used to establish the connection.
707+
# - {:port}[rdoc-ref:Net::HTTP#port]:
708+
# Returns the integer port number.
709+
#
710+
# === \HTTP Version
711+
#
712+
# - {::version_1_2?}[rdoc-ref:Net::HTTP.version_1_2?]
713+
# (aliased as {::is_version_1_2?}[rdoc-ref:Net::HTTP.is_version_1_2?]
714+
# and {::version_1_2}[rdoc-ref:Net::HTTP.version_1_2]):
715+
# Returns true; retained for compatibility.
716+
#
717+
# === Debugging
718+
#
719+
# - {#set_debug_output}[rdoc-ref:Net::HTTP#set_debug_output]:
720+
# Sets the output stream for debugging.
721+
#
457722
class HTTP < Protocol
458723

459724
# :stopdoc:
@@ -1494,7 +1759,7 @@ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
14941759
end
14951760

14961761
class << HTTP
1497-
# returns true if self is a class which was created by HTTP::Proxy.
1762+
# Returns true if self is a class which was created by HTTP::Proxy.
14981763
def proxy_class?
14991764
defined?(@is_proxy_class) ? @is_proxy_class : false
15001765
end

lib/net/http/net-http.gemspec

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
name = File.basename(__FILE__, ".gemspec")
44
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
5-
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
6-
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7-
end rescue nil
5+
file = File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")
6+
begin
7+
break File.foreach(file, mode: "rb") do |line|
8+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
9+
end
10+
rescue SystemCallError
11+
next
12+
end
813
end
914

1015
Gem::Specification.new do |spec|
@@ -25,7 +30,7 @@ Gem::Specification.new do |spec|
2530
# Specify which files should be added to the gem when it is released.
2631
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
2732
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28-
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33+
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{\A(?:(?:test|spec|features)/|\.git)}) }
2934
end
3035
spec.bindir = "exe"
3136
spec.require_paths = ["lib"]

lib/net/http/response.rb

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,32 @@ def initialize(httpv, code, msg) #:nodoc: internal use only
224224
# Accept-Encoding header from the user.
225225
attr_accessor :decode_content
226226

227-
# The encoding to use for the response body. If Encoding, use that encoding.
228-
# If other true value, attempt to detect the appropriate encoding, and use
229-
# that.
227+
# Returns the value set by body_encoding=, or +false+ if none;
228+
# see #body_encoding=.
230229
attr_reader :body_encoding
231230

232-
# Set the encoding to use for the response body. If given a String, find
233-
# the related Encoding.
231+
# Sets the encoding that should be used when reading the body:
232+
#
233+
# - If the given value is an Encoding object, that encoding will be used.
234+
# - Otherwise if the value is a string, the value of
235+
# {Encoding#find(value)}[rdoc-ref:Encoding.find]
236+
# will be used.
237+
# - Otherwise an encoding will be deduced from the body itself.
238+
#
239+
# Examples:
240+
#
241+
# http = Net::HTTP.new(hostname)
242+
# req = Net::HTTP::Get.new('/')
243+
#
244+
# http.request(req) do |res|
245+
# p res.body.encoding # => #<Encoding:ASCII-8BIT>
246+
# end
247+
#
248+
# http.request(req) do |res|
249+
# res.body_encoding = "UTF-8"
250+
# p res.body.encoding # => #<Encoding:UTF-8>
251+
# end
252+
#
234253
def body_encoding=(value)
235254
value = Encoding.find(value) if value.is_a?(String)
236255
@body_encoding = value
@@ -362,26 +381,26 @@ def read_body(dest = nil, &block)
362381
@body
363382
end
364383

365-
# Returns the full entity body.
384+
# Returns the string response body;
385+
# note that repeated calls for the unmodified body return a cached string:
366386
#
367-
# Calling this method a second or subsequent time will return the
368-
# string already read.
387+
# path = '/todos/1'
388+
# Net::HTTP.start(hostname) do |http|
389+
# res = http.get(path)
390+
# p res.body
391+
# p http.head(path).body # No body.
392+
# end
369393
#
370-
# http.request_get('/index.html') {|res|
371-
# puts res.body
372-
# }
394+
# Output:
373395
#
374-
# http.request_get('/index.html') {|res|
375-
# p res.body.object_id # 538149362
376-
# p res.body.object_id # 538149362
377-
# }
396+
# "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}"
397+
# nil
378398
#
379399
def body
380400
read_body()
381401
end
382402

383-
# Because it may be necessary to modify the body, Eg, decompression
384-
# this method facilitates that.
403+
# Sets the body of the response to the given value.
385404
def body=(value)
386405
@body = value
387406
end

0 commit comments

Comments
 (0)