Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Using Logger Breaks Request Streaming #785

Open
ksylvest opened this issue Jun 21, 2024 · 1 comment
Open

Bug: Using Logger Breaks Request Streaming #785

ksylvest opened this issue Jun 21, 2024 · 1 comment
Labels

Comments

@ksylvest
Copy link

ksylvest commented Jun 21, 2024

Per the documentation, it should be possible to pass a an each block to body to stream:

require 'http'
response = HTTP.get('https://news.ycombinator.com')
response.body.each { |chunk| puts(chunk) }

This works as expected. However, if logging is used then an HTTP::StateError is raised:

require 'http'
require 'logger'
logger = Logger.new($stdout)

response = HTTP.use({ logging: { logger: logger }}).get('https://news.ycombinator.com')
response.body.each { |chunk| puts(chunk) }
# raises: http/response/body.rb:67:in `stream!': body has already been consumed (HTTP::StateError)
@midnight-wonderer
Copy link
Contributor

I know you know what caused the error. (I read your other thread.)
I don't have a solution for HTTP.rb.

However, FWIW, just setting the log level should address your specific issue.

logger = Logger.new($stdout, level: Logger::INFO)

If you are okay with the level, of course.

@ixti ixti added the Bug label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants