From 8529ffa51ee47beacac504dca005eeb7e421169e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Marohni=C4=87?= Date: Wed, 23 May 2018 03:20:11 +0200 Subject: [PATCH] Stop writing after receiving Errno::EPIPE We want to stop writing after server has closed its end of the pipe (as no more data will be accepted) and proceed with reading the response. --- .rubocop.yml | 5 +++++ lib/http/request/writer.rb | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index c0f965fe..06c7710f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,11 @@ Layout/SpaceAroundOperators: Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space +## Lint ######################################################################## + +Lint/HandleExceptions: + Enabled: false + ## Metrics ##################################################################### Metrics/AbcSize: diff --git a/lib/http/request/writer.rb b/lib/http/request/writer.rb index ca770b4b..67a5a1d6 100644 --- a/lib/http/request/writer.rb +++ b/lib/http/request/writer.rb @@ -76,6 +76,8 @@ def send_request write(data) unless data.empty? write(CHUNKED_END) if chunked? + rescue Errno::EPIPE + # server doesn't need any more data end # Returns the chunk encoded for to the specified "Transfer-Encoding" header. @@ -101,7 +103,7 @@ def write(data) data = data.byteslice(length..-1) end rescue Errno::EPIPE - # server doesn't need any more data + raise # re-raise Errno::EPIPE rescue IOError, SocketError, SystemCallError => ex raise ConnectionError, "error writing to socket: #{ex}", ex.backtrace end