From e70f90eeb8c23be8e917fd680b0c03ed96020b40 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 20 Jun 2019 12:59:29 -0700 Subject: [PATCH] Ignore Errno::EPIPE when sending requests in net/http An EPIPE when sending the request should be ignored. Even if you cannot write more data, you may still be able to read the server's response. --- lib/net/http.rb | 8 +++++++- test/net/http/test_http.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index bc181c01af..663b901a96 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1504,7 +1504,13 @@ def transport_request(req) begin begin_transport req res = catch(:response) { - req.exec @socket, @curr_http_version, edit_path(req.path) + begin + req.exec @socket, @curr_http_version, edit_path(req.path) + rescue Errno::EPIPE + # Failure when writing full request, but we can probably + # still read the received response. + end + begin res = HTTPResponse.read_new(@socket) res.decode_content = req.decode_content diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 0344ad786b..c2d1e976a3 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -884,6 +884,17 @@ def new Net::HTTP.version_1_2 super end + + def test_send_large_POST_request + start {|http| + data = ' '*6000000 + res = http.send_request('POST', '/', data, 'content-type' => 'application/x-www-form-urlencoded') + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + assert_equal data.size, res.body.size + assert_equal data, res.body + } + end end class TestNetHTTP_v1_2_chunked < Test::Unit::TestCase -- 2.21.0