httplog icon indicating copy to clipboard operation
httplog copied to clipboard

Exception `Errno::ESPIPE` with chunked transfer encoding and pipe-io as body

Open eric-christian opened this issue 4 years ago • 1 comments

Describe the bug

Hello,

We encountered an Illegal seek (Errno::ESPIPE) exception while doing some chunked transfer encoding with a pipe-io as body. The exception is raised when the body is rewinded. While a pipe-io responses to rewind it actually can't be rewinded. https://github.com/trusche/httplog/blob/ae519ee46d61ef3bf31dca9073aaa12d8c752f02/lib/httplog/adapters/http.rb#L37

In the source of the http.rb gem is a comment as to what happens when rewind is called on a pipe-io. Maybe that explains it a little better. :) https://github.com/httprb/http/blob/a0f540ffd03b29bf35bd5476b82a20fb8c3b88b8/lib/http/request/body.rb#L57

Steps to reproduce

require 'http'
require 'httplog'

rd, wr = IO.pipe
wr.write('a chunk')
wr.close
HTTP.post('https://www.sumcumo.com', body: rd, headers: { 'Transfer-Encoding' => 'chunked' })

Expected behavior

Don't raise an exception while chunked transfer encoding with pipe-io as body is used.

Environment

  • Ruby version: 2.7.2
  • httplog version: 1.4.3
  • http version: 4.4.1

Have a great day! :)

Eric

eric-christian avatar Apr 13 '21 17:04 eric-christian

Ugh. Thanks for reporting. This is what I was afraid of when we first introduced support for streams - they need to be rewound because reading them is not idempotent. I'll take a closer look in a while - it might be we simply can't log the body content in this case.

trusche avatar Apr 17 '21 20:04 trusche