rails_api_logger icon indicating copy to clipboard operation
rails_api_logger copied to clipboard

undefined method `rewind' for an instance of Rackup::Handler::WEBrick::Input

Open mbajur opened this issue 9 months ago • 1 comments

Hey!

I'm trying to use rails_api_logger with my webrick-based rails app but when request comes in, app raises:

[2025-03-31 16:13:58] ERROR NoMethodError: undefined method `rewind' for an instance of Rackup::Handler::WEBrick::Input
	/Users/mbajur/.local/share/mise/installs/ruby/3.3.3/lib/ruby/gems/3.3.0/bundler/gems/rails_api_logger-f787839b5d4a/app/middlewares/rails_api_logger/middleware.rb:23:in `call'

I managed to fix that by changing this line to request.body.rewind if request.body.respond_to?(:rewind)

I can open a PR if you think that's a proper fix for the issue.

I'm on Ruby 3.3.3 and Rails 7.1.3.2

mbajur avatar Mar 31 '25 14:03 mbajur

Actually, it seems that after that change, RAL is not saving response status code nor body with InboundRequestLog

mbajur avatar Mar 31 '25 14:03 mbajur

I think this is related to the fact that Rack 3.0 bodies are not rewindable per default anymore. See Rack::RewindableInput::Middleware.

@coorasse are you using this gem anywhere with Rack 3.0 successfully?

schmijos avatar Jun 05 '25 20:06 schmijos

Yes, we use it in at least two apps with rack 3+

coorasse avatar Jun 06 '25 12:06 coorasse

@mbajur do you still have the issue after switching to puma?

coorasse avatar Jun 06 '25 12:06 coorasse

The issue is fixed now on webrick as well

coorasse avatar Aug 13 '25 13:08 coorasse