Project

General

Profile

Bug #11526 ยป no_retry_http_streams.diff

Patch that changes Net::HTTP behavior to only retry the request if a block is not given - tdg5 (Danny Guinther), 09/14/2015 07:12 PM

View differences:

lib/net/http.rb
1452 1452
             # avoid a dependency on OpenSSL
1453 1453
             defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
1454 1454
             Timeout::Error => exception
1455
        if count == 0 && IDEMPOTENT_METHODS_.include?(req.method)
1455
        if count == 0 && IDEMPOTENT_METHODS_.include?(req.method) && !block_given?
1456 1456
          count += 1
1457 1457
          @socket.close if @socket and not @socket.closed?
1458 1458
          D "Conn close because of error #{exception}, and retry"
test/net/http/test_http.rb
866 866
  include TestNetHTTPUtils
867 867

  
868 868
  def test_keep_alive_get_auto_reconnect
869
    start {|http|
869
    http = new
870
    res = http.get('/')
871
    http.keep_alive_timeout = 1
872
    assert_kind_of Net::HTTPResponse, res
873
    assert_kind_of String, res.body
874
    sleep 1.5
875
    assert_nothing_raised {
870 876
      res = http.get('/')
871
      http.keep_alive_timeout = 1
872
      assert_kind_of Net::HTTPResponse, res
873
      assert_kind_of String, res.body
874
      sleep 1.5
875
      assert_nothing_raised {
876
        res = http.get('/')
877
      }
878
      assert_kind_of Net::HTTPResponse, res
879
      assert_kind_of String, res.body
880 877
    }
878
    assert_kind_of Net::HTTPResponse, res
879
    assert_kind_of String, res.body
881 880
  end
882 881

  
883 882
  def test_keep_alive_get_auto_retry
884
    start {|http|
883
    http = new
884
    res = http.get('/')
885
    http.keep_alive_timeout = 5
886
    assert_kind_of Net::HTTPResponse, res
887
    assert_kind_of String, res.body
888
    sleep 1.5
889
    res = http.get('/')
890
    assert_kind_of Net::HTTPResponse, res
891
    assert_kind_of String, res.body
892
  end
893

  
894
  def test_keep_alive_no_auto_retry_block
895
    start do |http|
885 896
      res = http.get('/')
886 897
      http.keep_alive_timeout = 5
887 898
      assert_kind_of Net::HTTPResponse, res
888 899
      assert_kind_of String, res.body
889 900
      sleep 1.5
890
      res = http.get('/')
901
      assert_raises(EOFError) { res = http.get('/') }
891 902
      assert_kind_of Net::HTTPResponse, res
892 903
      assert_kind_of String, res.body
893
    }
904
    end
894 905
  end
895 906

  
896 907
  def test_keep_alive_server_close