net-http 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/net/http/header.rb +118 -59
- data/lib/net/http/responses.rb +479 -69
- data/lib/net/http.rb +312 -75
- metadata +2 -2
data/lib/net/http.rb
CHANGED
@@ -379,7 +379,7 @@ module Net #:nodoc:
|
|
379
379
|
class HTTP < Protocol
|
380
380
|
|
381
381
|
# :stopdoc:
|
382
|
-
VERSION = "0.3.
|
382
|
+
VERSION = "0.3.2"
|
383
383
|
Revision = %q$Revision$.split[1]
|
384
384
|
HTTPVersion = '1.1'
|
385
385
|
begin
|
@@ -452,6 +452,11 @@ module Net #:nodoc:
|
|
452
452
|
# headers = {'Content-type' => 'application/json; charset=UTF-8'}
|
453
453
|
# Net::HTTP.get(uri, headers)
|
454
454
|
#
|
455
|
+
# Related:
|
456
|
+
#
|
457
|
+
# - Net::HTTP::Get: request class for \HTTP method +GET+.
|
458
|
+
# - Net::HTTP#get: convenience method for \HTTP method +GET+.
|
459
|
+
#
|
455
460
|
def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
|
456
461
|
get_response(uri_or_host, path_or_headers, port).body
|
457
462
|
end
|
@@ -460,7 +465,7 @@ module Net #:nodoc:
|
|
460
465
|
# Net::HTTP.get_response(hostname, path, port = 80) -> http_response
|
461
466
|
# Net::HTTP:get_response(uri, headers = {}, port = uri.port) -> http_response
|
462
467
|
#
|
463
|
-
# Like Net::HTTP.get, but returns
|
468
|
+
# Like Net::HTTP.get, but returns a Net::HTTPResponse object
|
464
469
|
# instead of the body string.
|
465
470
|
def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
|
466
471
|
if path_or_headers && !path_or_headers.is_a?(Hash)
|
@@ -479,16 +484,31 @@ module Net #:nodoc:
|
|
479
484
|
end
|
480
485
|
end
|
481
486
|
|
482
|
-
# Posts data to
|
487
|
+
# Posts data to a host; returns a Net::HTTPResponse object.
|
483
488
|
#
|
484
|
-
#
|
489
|
+
# Argument +url+ must be a URL;
|
490
|
+
# argument +data+ must be a string:
|
485
491
|
#
|
486
|
-
#
|
487
|
-
#
|
492
|
+
# _uri = uri.dup
|
493
|
+
# _uri.path = '/posts'
|
494
|
+
# data = '{"title": "foo", "body": "bar", "userId": 1}'
|
495
|
+
# headers = {'content-type': 'application/json'}
|
496
|
+
# res = Net::HTTP.post(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true>
|
497
|
+
# puts res.body
|
488
498
|
#
|
489
|
-
#
|
490
|
-
#
|
491
|
-
#
|
499
|
+
# Output:
|
500
|
+
#
|
501
|
+
# {
|
502
|
+
# "title": "foo",
|
503
|
+
# "body": "bar",
|
504
|
+
# "userId": 1,
|
505
|
+
# "id": 101
|
506
|
+
# }
|
507
|
+
#
|
508
|
+
# Related:
|
509
|
+
#
|
510
|
+
# - Net::HTTP::Post: request class for \HTTP method +POST+.
|
511
|
+
# - Net::HTTP#post: convenience method for \HTTP method +POST+.
|
492
512
|
#
|
493
513
|
def HTTP.post(url, data, header = nil)
|
494
514
|
start(url.hostname, url.port,
|
@@ -497,22 +517,25 @@ module Net #:nodoc:
|
|
497
517
|
}
|
498
518
|
end
|
499
519
|
|
500
|
-
# Posts
|
501
|
-
# The form data must be provided as a Hash mapping from String to String.
|
502
|
-
# Example:
|
520
|
+
# Posts data to a host; returns a Net::HTTPResponse object.
|
503
521
|
#
|
504
|
-
#
|
522
|
+
# Argument +url+ must be a URI;
|
523
|
+
# argument +data+ must be a hash:
|
505
524
|
#
|
506
|
-
#
|
507
|
-
#
|
508
|
-
#
|
525
|
+
# _uri = uri.dup
|
526
|
+
# _uri.path = '/posts'
|
527
|
+
# data = {title: 'foo', body: 'bar', userId: 1}
|
528
|
+
# res = Net::HTTP.post_form(_uri, data) # => #<Net::HTTPCreated 201 Created readbody=true>
|
529
|
+
# puts res.body
|
509
530
|
#
|
510
|
-
#
|
511
|
-
#
|
512
|
-
# require 'net/http'
|
531
|
+
# Output:
|
513
532
|
#
|
514
|
-
#
|
515
|
-
#
|
533
|
+
# {
|
534
|
+
# "title": "foo",
|
535
|
+
# "body": "bar",
|
536
|
+
# "userId": "1",
|
537
|
+
# "id": 101
|
538
|
+
# }
|
516
539
|
#
|
517
540
|
def HTTP.post_form(url, params)
|
518
541
|
req = Post.new(url)
|
@@ -528,17 +551,26 @@ module Net #:nodoc:
|
|
528
551
|
# HTTP session management
|
529
552
|
#
|
530
553
|
|
531
|
-
#
|
554
|
+
# Returns intger +80+, the default port to use for HTTP requests:
|
555
|
+
#
|
556
|
+
# Net::HTTP.default_port # => 80
|
557
|
+
#
|
532
558
|
def HTTP.default_port
|
533
559
|
http_default_port()
|
534
560
|
end
|
535
561
|
|
536
|
-
#
|
562
|
+
# Returns integer +80+, the default port to use for HTTP requests:
|
563
|
+
#
|
564
|
+
# Net::HTTP.http_default_port # => 80
|
565
|
+
#
|
537
566
|
def HTTP.http_default_port
|
538
567
|
80
|
539
568
|
end
|
540
569
|
|
541
|
-
#
|
570
|
+
# Returns integer +443+, the default port to use for HTTPS requests:
|
571
|
+
#
|
572
|
+
# Net::HTTP.https_default_port # => 443
|
573
|
+
#
|
542
574
|
def HTTP.https_default_port
|
543
575
|
443
|
544
576
|
end
|
@@ -548,19 +580,42 @@ module Net #:nodoc:
|
|
548
580
|
end
|
549
581
|
|
550
582
|
# :call-seq:
|
551
|
-
# HTTP.start(address, port, p_addr, p_port, p_user, p_pass)
|
552
|
-
# HTTP.start(address, port=nil, p_addr
|
553
|
-
# Creates a new \Net::HTTP object,
|
554
|
-
# opens a TCP connection and \HTTP session.
|
583
|
+
# HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) -> http
|
584
|
+
# HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) {|http| ... } -> object
|
555
585
|
#
|
556
|
-
#
|
586
|
+
# Creates a new \Net::HTTP object, +http+, via \Net::HTTP.new:
|
587
|
+
#
|
588
|
+
# Net::HTTP.new(address, port, p_addr, p_port, p_user, p_pass)
|
589
|
+
#
|
590
|
+
# - For arguments +hostname+ through +p_pass+, see Net::HTTP.new.
|
591
|
+
# - For argument +opts+, see below.
|
592
|
+
#
|
593
|
+
# Note: If +port+ is +nil+ and <tt>opts[:use_ssl]</tt> is a truthy value,
|
594
|
+
# the value passed to +new+ is Net::HTTP.https_default_port, not +port+.
|
595
|
+
#
|
596
|
+
# With no block given:
|
597
|
+
#
|
598
|
+
# - Calls <tt>http.start</tt> with no block (see #start),
|
599
|
+
# which opens a TCP connection and \HTTP session.
|
600
|
+
# - Returns +http+.
|
601
|
+
# - The caller should call #finish to close the session:
|
602
|
+
#
|
603
|
+
# http = Net::HTTP.start(hostname)
|
604
|
+
# http.started? # => true
|
605
|
+
# http.finish
|
606
|
+
# http.started? # => false
|
557
607
|
#
|
558
608
|
# With a block given:
|
559
609
|
#
|
560
|
-
# -
|
561
|
-
#
|
562
|
-
#
|
563
|
-
#
|
610
|
+
# - Calls <tt>http.start</tt> with the block (see #start), which:
|
611
|
+
#
|
612
|
+
# - Opens a TCP connection and \HTTP session.
|
613
|
+
# - Calls the block,
|
614
|
+
# which may make any number of requests to the host.
|
615
|
+
# - Closes the \HTTP session and TCP connection on block exit.
|
616
|
+
# - Returns the block's value +object+.
|
617
|
+
#
|
618
|
+
# - Returns +object+.
|
564
619
|
#
|
565
620
|
# Example:
|
566
621
|
#
|
@@ -585,19 +640,7 @@ module Net #:nodoc:
|
|
585
640
|
# "completed": false
|
586
641
|
# }
|
587
642
|
#
|
588
|
-
#
|
589
|
-
# the caller should call #finish to close the session.
|
590
|
-
#
|
591
|
-
# Other arguments:
|
592
|
-
#
|
593
|
-
# - +port+: Server port number.
|
594
|
-
# - +p_addr+: Proxy address.
|
595
|
-
# - +p_port+: Proxy port.
|
596
|
-
# - +p_user+: Proxy user name.
|
597
|
-
# - +p_pass+: Proxy password.
|
598
|
-
# - +opts+: Optional options hash.
|
599
|
-
#
|
600
|
-
# The options hash +opts+ sets certain values,
|
643
|
+
# If the last argument given is a hash, it is the +opts+ hash,
|
601
644
|
# where each key is a method or accessor to be called,
|
602
645
|
# and its value is the value to be set.
|
603
646
|
#
|
@@ -648,25 +691,113 @@ module Net #:nodoc:
|
|
648
691
|
alias newobj new # :nodoc:
|
649
692
|
end
|
650
693
|
|
651
|
-
#
|
652
|
-
# HTTP session.
|
694
|
+
# Returns a new Net::HTTP object +http+
|
695
|
+
# (but does not open a TCP connection or HTTP session).
|
696
|
+
#
|
697
|
+
# <b>No Proxy</b>
|
698
|
+
#
|
699
|
+
# With only string argument +hostname+ given
|
700
|
+
# (and <tt>ENV['http_proxy']</tt> undefined or +nil+),
|
701
|
+
# the returned +http+:
|
702
|
+
#
|
703
|
+
# - Has the given address.
|
704
|
+
# - Has the default port number, Net::HTTP.default_port (80).
|
705
|
+
# - Has no proxy.
|
706
|
+
#
|
707
|
+
# Example:
|
708
|
+
#
|
709
|
+
# http = Net::HTTP.new(hostname)
|
710
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
|
711
|
+
# http.address # => "jsonplaceholder.typicode.com"
|
712
|
+
# http.port # => 80
|
713
|
+
# http.proxy? # => false
|
714
|
+
#
|
715
|
+
# With integer argument +port+ also given,
|
716
|
+
# the returned +http+ has the given port:
|
717
|
+
#
|
718
|
+
# http = Net::HTTP.new(hostname, 8000)
|
719
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:8000 open=false>
|
720
|
+
# http.port # => 8000
|
721
|
+
#
|
722
|
+
# <b>Proxy Using Argument +p_addr+ as a \String</b>
|
723
|
+
#
|
724
|
+
# When argument +p_addr+ is a string hostname,
|
725
|
+
# the returned +http+ has a proxy:
|
726
|
+
#
|
727
|
+
# http = Net::HTTP.new(hostname, nil, 'proxy.example')
|
728
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
|
729
|
+
# http.proxy? # => true
|
730
|
+
# http.proxy_address # => "proxy.example"
|
731
|
+
# # These use default values.
|
732
|
+
# http.proxy_port # => 80
|
733
|
+
# http.proxy_user # => nil
|
734
|
+
# http.proxy_pass # => nil
|
735
|
+
#
|
736
|
+
# The port, username, and password for the proxy may also be given:
|
737
|
+
#
|
738
|
+
# http = Net::HTTP.new(hostname, nil, 'proxy.example', 8000, 'pname', 'ppass')
|
739
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
|
740
|
+
# http.proxy? # => true
|
741
|
+
# http.proxy_address # => "proxy.example"
|
742
|
+
# http.proxy_port # => 8000
|
743
|
+
# http.proxy_user # => "pname"
|
744
|
+
# http.proxy_pass # => "ppass"
|
745
|
+
#
|
746
|
+
# <b>Proxy Using <tt>ENV['http_proxy']</tt></b>
|
747
|
+
#
|
748
|
+
# When environment variable <tt>'http_proxy'</tt>
|
749
|
+
# is set to a \URI string,
|
750
|
+
# the returned +http+ will have that URI as its proxy;
|
751
|
+
# note that the \URI string must have a protocol
|
752
|
+
# such as <tt>'http'</tt> or <tt>'https'</tt>:
|
753
|
+
#
|
754
|
+
# ENV['http_proxy'] = 'http://example.com'
|
755
|
+
# # => "http://example.com"
|
756
|
+
# http = Net::HTTP.new(hostname)
|
757
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
|
758
|
+
# http.proxy? # => true
|
759
|
+
# http.address # => "jsonplaceholder.typicode.com"
|
760
|
+
# http.proxy_address # => "example.com"
|
761
|
+
#
|
762
|
+
# The \URI string may include proxy username, password, and port number:
|
763
|
+
#
|
764
|
+
# ENV['http_proxy'] = 'http://pname:ppass@example.com:8000'
|
765
|
+
# # => "http://pname:ppass@example.com:8000"
|
766
|
+
# http = Net::HTTP.new(hostname)
|
767
|
+
# # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
|
768
|
+
# http.proxy_port # => 8000
|
769
|
+
# http.proxy_user # => "pname"
|
770
|
+
# http.proxy_pass # => "ppass"
|
771
|
+
#
|
772
|
+
# <b>Argument +p_no_proxy+</b>
|
773
|
+
#
|
774
|
+
# You can use argument +p_no_proxy+ to reject certain proxies:
|
775
|
+
#
|
776
|
+
# - Reject a certain address:
|
777
|
+
#
|
778
|
+
# http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
|
779
|
+
# http.proxy_address # => nil
|
780
|
+
#
|
781
|
+
# - Reject certain domains or subdomains:
|
653
782
|
#
|
654
|
-
#
|
655
|
-
#
|
656
|
-
# HTTP or HTTPS is used.
|
783
|
+
# http = Net::HTTP.new('example.com', nil, 'my.proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
|
784
|
+
# http.proxy_address # => nil
|
657
785
|
#
|
658
|
-
#
|
659
|
-
# taken from the +http_proxy+ environment variable (or its uppercase
|
660
|
-
# equivalent) if present. If the proxy requires authentication you must
|
661
|
-
# supply it by hand. See URI::Generic#find_proxy for details of proxy
|
662
|
-
# detection from the environment. To disable proxy detection set +p_addr+
|
663
|
-
# to nil.
|
786
|
+
# - Reject certain addresses and port combinations:
|
664
787
|
#
|
665
|
-
#
|
666
|
-
#
|
667
|
-
#
|
668
|
-
#
|
669
|
-
#
|
788
|
+
# http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:1234')
|
789
|
+
# http.proxy_address # => "proxy.example"
|
790
|
+
#
|
791
|
+
# http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:8000')
|
792
|
+
# http.proxy_address # => nil
|
793
|
+
#
|
794
|
+
# - Reject a list of the types above delimited using a comma:
|
795
|
+
#
|
796
|
+
# http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
|
797
|
+
# http.proxy_address # => nil
|
798
|
+
#
|
799
|
+
# http = Net::HTTP.new('example.com', nil, 'my.proxy', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
|
800
|
+
# http.proxy_address # => nil
|
670
801
|
#
|
671
802
|
def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil)
|
672
803
|
http = super address, port
|
@@ -733,6 +864,11 @@ module Net #:nodoc:
|
|
733
864
|
end
|
734
865
|
end
|
735
866
|
|
867
|
+
# Returns a string representation of +self+:
|
868
|
+
#
|
869
|
+
# Net::HTTP.new(hostname).inspect
|
870
|
+
# # => "#<Net::HTTP jsonplaceholder.typicode.com:80 open=false>"
|
871
|
+
#
|
736
872
|
def inspect
|
737
873
|
"#<#{self.class} #{@address}:#{@port} open=#{started?}>"
|
738
874
|
end
|
@@ -740,11 +876,51 @@ module Net #:nodoc:
|
|
740
876
|
# *WARNING* This method opens a serious security hole.
|
741
877
|
# Never use this method in production code.
|
742
878
|
#
|
743
|
-
# Sets
|
879
|
+
# Sets the output stream for debugging:
|
744
880
|
#
|
745
881
|
# http = Net::HTTP.new(hostname)
|
746
|
-
#
|
747
|
-
#
|
882
|
+
# File.open('t.tmp', 'w') do |file|
|
883
|
+
# http.set_debug_output(file)
|
884
|
+
# http.start
|
885
|
+
# http.get('/nosuch/1')
|
886
|
+
# http.finish
|
887
|
+
# end
|
888
|
+
# puts File.read('t.tmp')
|
889
|
+
#
|
890
|
+
# Output:
|
891
|
+
#
|
892
|
+
# opening connection to jsonplaceholder.typicode.com:80...
|
893
|
+
# opened
|
894
|
+
# <- "GET /nosuch/1 HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nHost: jsonplaceholder.typicode.com\r\n\r\n"
|
895
|
+
# -> "HTTP/1.1 404 Not Found\r\n"
|
896
|
+
# -> "Date: Mon, 12 Dec 2022 21:14:11 GMT\r\n"
|
897
|
+
# -> "Content-Type: application/json; charset=utf-8\r\n"
|
898
|
+
# -> "Content-Length: 2\r\n"
|
899
|
+
# -> "Connection: keep-alive\r\n"
|
900
|
+
# -> "X-Powered-By: Express\r\n"
|
901
|
+
# -> "X-Ratelimit-Limit: 1000\r\n"
|
902
|
+
# -> "X-Ratelimit-Remaining: 999\r\n"
|
903
|
+
# -> "X-Ratelimit-Reset: 1670879660\r\n"
|
904
|
+
# -> "Vary: Origin, Accept-Encoding\r\n"
|
905
|
+
# -> "Access-Control-Allow-Credentials: true\r\n"
|
906
|
+
# -> "Cache-Control: max-age=43200\r\n"
|
907
|
+
# -> "Pragma: no-cache\r\n"
|
908
|
+
# -> "Expires: -1\r\n"
|
909
|
+
# -> "X-Content-Type-Options: nosniff\r\n"
|
910
|
+
# -> "Etag: W/\"2-vyGp6PvFo4RvsFtPoIWeCReyIC8\"\r\n"
|
911
|
+
# -> "Via: 1.1 vegur\r\n"
|
912
|
+
# -> "CF-Cache-Status: MISS\r\n"
|
913
|
+
# -> "Server-Timing: cf-q-config;dur=1.3000000762986e-05\r\n"
|
914
|
+
# -> "Report-To: {\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=yOr40jo%2BwS1KHzhTlVpl54beJ5Wx2FcG4gGV0XVrh3X9OlR5q4drUn2dkt5DGO4GDcE%2BVXT7CNgJvGs%2BZleIyMu8CLieFiDIvOviOY3EhHg94m0ZNZgrEdpKD0S85S507l1vsEwEHkoTm%2Ff19SiO\"}],\"group\":\"cf-nel\",\"max_age\":604800}\r\n"
|
915
|
+
# -> "NEL: {\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}\r\n"
|
916
|
+
# -> "Server: cloudflare\r\n"
|
917
|
+
# -> "CF-RAY: 778977dc484ce591-DFW\r\n"
|
918
|
+
# -> "alt-svc: h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400\r\n"
|
919
|
+
# -> "\r\n"
|
920
|
+
# reading 2 bytes...
|
921
|
+
# -> "{}"
|
922
|
+
# read 2 bytes
|
923
|
+
# Conn keep-alive
|
748
924
|
#
|
749
925
|
def set_debug_output(output)
|
750
926
|
warn 'Net::HTTP#set_debug_output called after HTTP started', uplevel: 1 if started?
|
@@ -768,8 +944,24 @@ module Net #:nodoc:
|
|
768
944
|
# body encoding.
|
769
945
|
attr_reader :response_body_encoding
|
770
946
|
|
771
|
-
#
|
772
|
-
# the
|
947
|
+
# Sets the encoding to be used for the response body;
|
948
|
+
# returns the encoding.
|
949
|
+
#
|
950
|
+
# The given +value+ may be:
|
951
|
+
#
|
952
|
+
# - An Encoding object.
|
953
|
+
# - The name of an encoding.
|
954
|
+
# - An alias for an encoding name.
|
955
|
+
#
|
956
|
+
# See {Encoding}[https://docs.ruby-lang.org/en/master/Encoding.html].
|
957
|
+
#
|
958
|
+
# Examples:
|
959
|
+
#
|
960
|
+
# http = Net::HTTP.new(hostname)
|
961
|
+
# http.response_body_encoding = Encoding::US_ASCII # => #<Encoding:US-ASCII>
|
962
|
+
# http.response_body_encoding = 'US-ASCII' # => "US-ASCII"
|
963
|
+
# http.response_body_encoding = 'ASCII' # => "ASCII"
|
964
|
+
#
|
773
965
|
def response_body_encoding=(value)
|
774
966
|
value = Encoding.find(value) if value.is_a?(String)
|
775
967
|
@response_body_encoding = value
|
@@ -781,12 +973,37 @@ module Net #:nodoc:
|
|
781
973
|
attr_writer :proxy_user
|
782
974
|
attr_writer :proxy_pass
|
783
975
|
|
784
|
-
#
|
976
|
+
# Returns the IP address for the connection.
|
977
|
+
#
|
978
|
+
# If the session has not been started,
|
979
|
+
# returns the value set by #ipaddr=,
|
980
|
+
# or +nil+ if it has not been set:
|
981
|
+
#
|
982
|
+
# http = Net::HTTP.new(hostname)
|
983
|
+
# http.ipaddr # => nil
|
984
|
+
# http.ipaddr = '172.67.155.76'
|
985
|
+
# http.ipaddr # => "172.67.155.76"
|
986
|
+
#
|
987
|
+
# If the session has been started,
|
988
|
+
# returns the IP address from the socket:
|
989
|
+
#
|
990
|
+
# http = Net::HTTP.new(hostname)
|
991
|
+
# http.start
|
992
|
+
# http.ipaddr # => "172.67.155.76"
|
993
|
+
# http.finish
|
994
|
+
#
|
785
995
|
def ipaddr
|
786
996
|
started? ? @socket.io.peeraddr[3] : @ipaddr
|
787
997
|
end
|
788
998
|
|
789
|
-
#
|
999
|
+
# Sets the IP address for the connection:
|
1000
|
+
#
|
1001
|
+
# http = Net::HTTP.new(hostname)
|
1002
|
+
# http.ipaddr # => nil
|
1003
|
+
# http.ipaddr = '172.67.155.76'
|
1004
|
+
# http.ipaddr # => "172.67.155.76"
|
1005
|
+
#
|
1006
|
+
# The IP address may not be set if the session has been started.
|
790
1007
|
def ipaddr=(addr)
|
791
1008
|
raise IOError, "ipaddr value changed, but session already started" if started?
|
792
1009
|
@ipaddr = addr
|
@@ -811,12 +1028,18 @@ module Net #:nodoc:
|
|
811
1028
|
# Net::WriteTimeout is not raised on Windows.
|
812
1029
|
attr_reader :write_timeout
|
813
1030
|
|
814
|
-
#
|
1031
|
+
# Sets the maximum number of times to retry an idempotent request in case of
|
815
1032
|
# Net::ReadTimeout, IOError, EOFError, Errno::ECONNRESET,
|
816
1033
|
# Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError,
|
817
1034
|
# Timeout::Error.
|
818
|
-
#
|
819
|
-
#
|
1035
|
+
# The initial value is 1.
|
1036
|
+
#
|
1037
|
+
# Argument +retries+ must be a non-negative numeric value:
|
1038
|
+
#
|
1039
|
+
# http = Net::HTTP.new(hostname)
|
1040
|
+
# http.max_retries = 2 # => 2
|
1041
|
+
# http.max_retries # => 2
|
1042
|
+
#
|
820
1043
|
def max_retries=(retries)
|
821
1044
|
retries = retries.to_int
|
822
1045
|
if retries < 0
|
@@ -827,13 +1050,27 @@ module Net #:nodoc:
|
|
827
1050
|
|
828
1051
|
attr_reader :max_retries
|
829
1052
|
|
830
|
-
#
|
1053
|
+
# Sets the read timeout, in seconds, for +self+ to integer +sec+;
|
1054
|
+
# the initial value is 60.
|
1055
|
+
#
|
1056
|
+
# Argument +sec+ must be a non-negative numeric value:
|
1057
|
+
#
|
1058
|
+
# http = Net::HTTP.new(hostname)
|
1059
|
+
# http.read_timeout # => 60
|
1060
|
+
# http.get('/todos/1') # => #<Net::HTTPOK 200 OK readbody=true>
|
1061
|
+
# http.read_timeout = 0
|
1062
|
+
# http.get('/todos/1') # Raises Net::ReadTimeout.
|
1063
|
+
#
|
831
1064
|
def read_timeout=(sec)
|
832
1065
|
@socket.read_timeout = sec if @socket
|
833
1066
|
@read_timeout = sec
|
834
1067
|
end
|
835
1068
|
|
836
|
-
#
|
1069
|
+
# Sets the write timeout, in seconds, for +self+ to integer +sec+;
|
1070
|
+
# the initial value is 60.
|
1071
|
+
#
|
1072
|
+
# Argument +sec+ must be a non-negative numeric value.
|
1073
|
+
#
|
837
1074
|
def write_timeout=(sec)
|
838
1075
|
@socket.write_timeout = sec if @socket
|
839
1076
|
@write_timeout = sec
|
@@ -1160,7 +1397,7 @@ module Net #:nodoc:
|
|
1160
1397
|
#
|
1161
1398
|
# This class is obsolete. You may pass these same parameters directly to
|
1162
1399
|
# Net::HTTP.new. See Net::HTTP.new for details of the arguments.
|
1163
|
-
def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil)
|
1400
|
+
def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
|
1164
1401
|
return self unless p_addr
|
1165
1402
|
|
1166
1403
|
Class.new(self) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NARUSE, Yui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uri
|