@@ -332,20 +332,101 @@ class HTTPHeaderSyntaxError < StandardError; end
332
332
# uri # => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
333
333
# Net::HTTP.get(uri)
334
334
#
335
- # == Proxies
335
+ # == Proxy Server
336
336
#
337
- # \Net::HTTP will automatically create a proxy from the +http_proxy+
338
- # environment variable if it is present. To disable use of +http_proxy+,
339
- # pass +nil+ for the proxy address.
337
+ # An \HTTP object can have
338
+ # a {proxy server}[https://en.wikipedia.org/wiki/Proxy_server].
340
339
#
341
- # You may also create a custom proxy:
340
+ # You can create an \HTTP object with a proxy server
341
+ # using method Net::HTTP.new or method Net::HTTP.start.
342
342
#
343
- # proxy_addr = 'your.proxy.host'
344
- # proxy_port = 8080
343
+ # The proxy may be defined either by argument +p_addr+
344
+ # or by environment variable <tt>'http_proxy'</tt>.
345
345
#
346
- # Net::HTTP.new('example.com', nil, proxy_addr, proxy_port).start { |http|
347
- # # always proxy via your.proxy.addr:8080
348
- # }
346
+ # === Proxy Using Argument +p_addr+ as a \String
347
+ #
348
+ # When argument +p_addr+ is a string hostname,
349
+ # the returned +http+ has the given host as its proxy:
350
+ #
351
+ # http = Net::HTTP.new(hostname, nil, 'proxy.example')
352
+ # http.proxy? # => true
353
+ # http.proxy_from_env? # => false
354
+ # http.proxy_address # => "proxy.example"
355
+ # # These use default values.
356
+ # http.proxy_port # => 80
357
+ # http.proxy_user # => nil
358
+ # http.proxy_pass # => nil
359
+ #
360
+ # The port, username, and password for the proxy may also be given:
361
+ #
362
+ # http = Net::HTTP.new(hostname, nil, 'proxy.example', 8000, 'pname', 'ppass')
363
+ # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
364
+ # http.proxy? # => true
365
+ # http.proxy_from_env? # => false
366
+ # http.proxy_address # => "proxy.example"
367
+ # http.proxy_port # => 8000
368
+ # http.proxy_user # => "pname"
369
+ # http.proxy_pass # => "ppass"
370
+ #
371
+ # === Proxy Using <tt>ENV['http_proxy']</tt>
372
+ #
373
+ # When environment variable <tt>'http_proxy'</tt>
374
+ # is set to a \URI string,
375
+ # the returned +http+ will have the server at that URI as its proxy;
376
+ # note that the \URI string must have a protocol
377
+ # such as <tt>'http'</tt> or <tt>'https'</tt>:
378
+ #
379
+ # ENV['http_proxy'] = 'http://example.com'
380
+ # http = Net::HTTP.new(hostname)
381
+ # http.proxy? # => true
382
+ # http.proxy_from_env? # => true
383
+ # http.proxy_address # => "example.com"
384
+ # # These use default values.
385
+ # http.proxy_port # => 80
386
+ # http.proxy_user # => nil
387
+ # http.proxy_pass # => nil
388
+ #
389
+ # The \URI string may include proxy username, password, and port number:
390
+ #
391
+ # ENV['http_proxy'] = 'http://pname:[email protected] :8000'
392
+ # http = Net::HTTP.new(hostname)
393
+ # http.proxy? # => true
394
+ # http.proxy_from_env? # => true
395
+ # http.proxy_address # => "example.com"
396
+ # http.proxy_port # => 8000
397
+ # http.proxy_user # => "pname"
398
+ # http.proxy_pass # => "ppass"
399
+ #
400
+ # === Filtering Proxies
401
+ #
402
+ # With method Net::HTTP.new (but not Net::HTTP.start),
403
+ # you can use argument +p_no_proxy+ to filter proxies:
404
+ #
405
+ # - Reject a certain address:
406
+ #
407
+ # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
408
+ # http.proxy_address # => nil
409
+ #
410
+ # - Reject certain domains or subdomains:
411
+ #
412
+ # http = Net::HTTP.new('example.com', nil, 'my.proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
413
+ # http.proxy_address # => nil
414
+ #
415
+ # - Reject certain addresses and port combinations:
416
+ #
417
+ # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:1234')
418
+ # http.proxy_address # => "proxy.example"
419
+ #
420
+ # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:8000')
421
+ # http.proxy_address # => nil
422
+ #
423
+ # - Reject a list of the types above delimited using a comma:
424
+ #
425
+ # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
426
+ # http.proxy_address # => nil
427
+ #
428
+ # http = Net::HTTP.new('example.com', nil, 'my.proxy', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
429
+ # http.proxy_address # => nil
349
430
#
350
431
# == Compression
351
432
#
@@ -564,14 +645,11 @@ def HTTP.socket_type #:nodoc: obsolete
564
645
#
565
646
# Creates a new \Net::HTTP object, +http+, via \Net::HTTP.new:
566
647
#
567
- # Net::HTTP.new( address, port, p_addr, p_port, p_user, p_pass)
568
- #
569
- # - For arguments +hostname+ through +p_pass+, see Net::HTTP.new .
648
+ # - For arguments + address+ and + port+, see Net::HTTP.new.
649
+ # - For proxy-defining arguments +p_addr+ through +p_pass+,
650
+ # see {Proxy Server}[rdoc-ref: Net::HTTP@Proxy+Server] .
570
651
# - For argument +opts+, see below.
571
652
#
572
- # Note: If +port+ is +nil+ and <tt>opts[:use_ssl]</tt> is a truthy value,
573
- # the value passed to +new+ is Net::HTTP.https_default_port, not +port+.
574
- #
575
653
# With no block given:
576
654
#
577
655
# - Calls <tt>http.start</tt> with no block (see #start),
@@ -644,6 +722,9 @@ def HTTP.socket_type #:nodoc: obsolete
644
722
# - #verify_mode
645
723
# - #write_timeout
646
724
#
725
+ # Note: If +port+ is +nil+ and <tt>opts[:use_ssl]</tt> is a truthy value,
726
+ # the value passed to +new+ is Net::HTTP.https_default_port, not +port+.
727
+ #
647
728
def HTTP . start ( address , *arg , &block ) # :yield: +http+
648
729
arg . pop if opt = Hash . try_convert ( arg [ -1 ] )
649
730
port , p_addr , p_port , p_user , p_pass = *arg
@@ -673,9 +754,7 @@ class << HTTP
673
754
# Returns a new \Net::HTTP object +http+
674
755
# (but does not open a TCP connection or \HTTP session).
675
756
#
676
- # <b>No Proxy</b>
677
- #
678
- # With only string argument +hostname+ given
757
+ # With only string argument +address+ given
679
758
# (and <tt>ENV['http_proxy']</tt> undefined or +nil+),
680
759
# the returned +http+:
681
760
#
@@ -698,85 +777,8 @@ class << HTTP
698
777
# # => #<Net::HTTP jsonplaceholder.typicode.com:8000 open=false>
699
778
# http.port # => 8000
700
779
#
701
- # <b>Proxy Using Argument +p_addr+ as a \String</b>
702
- #
703
- # When argument +p_addr+ is a string hostname,
704
- # the returned +http+ has a proxy:
705
- #
706
- # http = Net::HTTP.new(hostname, nil, 'proxy.example')
707
- # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
708
- # http.proxy? # => true
709
- # http.proxy_address # => "proxy.example"
710
- # # These use default values.
711
- # http.proxy_port # => 80
712
- # http.proxy_user # => nil
713
- # http.proxy_pass # => nil
714
- #
715
- # The port, username, and password for the proxy may also be given:
716
- #
717
- # http = Net::HTTP.new(hostname, nil, 'proxy.example', 8000, 'pname', 'ppass')
718
- # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
719
- # http.proxy? # => true
720
- # http.proxy_address # => "proxy.example"
721
- # http.proxy_port # => 8000
722
- # http.proxy_user # => "pname"
723
- # http.proxy_pass # => "ppass"
724
- #
725
- # <b>Proxy Using <tt>ENV['http_proxy']</tt></b>
726
- #
727
- # When environment variable <tt>'http_proxy'</tt>
728
- # is set to a \URI string,
729
- # the returned +http+ will have that URI as its proxy;
730
- # note that the \URI string must have a protocol
731
- # such as <tt>'http'</tt> or <tt>'https'</tt>:
732
- #
733
- # ENV['http_proxy'] = 'http://example.com'
734
- # # => "http://example.com"
735
- # http = Net::HTTP.new(hostname)
736
- # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
737
- # http.proxy? # => true
738
- # http.address # => "jsonplaceholder.typicode.com"
739
- # http.proxy_address # => "example.com"
740
- #
741
- # The \URI string may include proxy username, password, and port number:
742
- #
743
- # ENV['http_proxy'] = 'http://pname:[email protected] :8000'
744
- # # => "http://pname:[email protected] :8000"
745
- # http = Net::HTTP.new(hostname)
746
- # # => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
747
- # http.proxy_port # => 8000
748
- # http.proxy_user # => "pname"
749
- # http.proxy_pass # => "ppass"
750
- #
751
- # <b>Argument +p_no_proxy+</b>
752
- #
753
- # You can use argument +p_no_proxy+ to reject certain proxies:
754
- #
755
- # - Reject a certain address:
756
- #
757
- # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
758
- # http.proxy_address # => nil
759
- #
760
- # - Reject certain domains or subdomains:
761
- #
762
- # http = Net::HTTP.new('example.com', nil, 'my.proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
763
- # http.proxy_address # => nil
764
- #
765
- # - Reject certain addresses and port combinations:
766
- #
767
- # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:1234')
768
- # http.proxy_address # => "proxy.example"
769
- #
770
- # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:8000')
771
- # http.proxy_address # => nil
772
- #
773
- # - Reject a list of the types above delimited using a comma:
774
- #
775
- # http = Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
776
- # http.proxy_address # => nil
777
- #
778
- # http = Net::HTTP.new('example.com', nil, 'my.proxy', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
779
- # http.proxy_address # => nil
780
+ # For proxy-defining arguments +p_addr+ through +p_no_proxy+,
781
+ # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
780
782
#
781
783
def HTTP . new ( address , port = nil , p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_no_proxy = nil )
782
784
http = super address , port
0 commit comments