From 7ef493da9486bf1be27157178ef23bf666ab8f26 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Mon, 24 Jan 2022 11:53:55 -0700 Subject: [PATCH] Return a `Rack::BodyProxy` from the `Rails::Rack::Logger` monkey patch (#333) * Return a `Rack::BodyProxy` from the `Rails::Rack::Logger` monkey patch This should return the same object that Rails is returning. See https://github.com/rails/rails/blob/8d1b8e870c1c42859132c8d51ceff0ac72cbe34b/railties/lib/rails/rack/logger.rb#L38 * Update lib/lograge/rails_ext/rack/logger.rb * Update CHANGELOG.md * Update logger.rb --- CHANGELOG.md | 4 ++++ lib/lograge/rails_ext/rack/logger.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5effc384..a67addeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +### Unreleased + +* Return a `Rack::BodyProxy` from the `Rails::Rack::Logger` monkey patch, this ensures the same return type as Rails [#333](https://github.com/roidrage/lograge/pull/333) + ### 0.11.2 * Resolve a bug with Action Cable registration [#286](https://github.com/roidrage/lograge/pull/286) diff --git a/lib/lograge/rails_ext/rack/logger.rb b/lib/lograge/rails_ext/rack/logger.rb index 38c937da..8d045315 100644 --- a/lib/lograge/rails_ext/rack/logger.rb +++ b/lib/lograge/rails_ext/rack/logger.rb @@ -15,7 +15,9 @@ class Logger # Overwrites Rails code that logs new requests def call_app(*args) env = args.last - @app.call(env) + status, headers, body = @app.call(env) + # needs to have same return type as the Rails builtins being overridden, see https://github.com/roidrage/lograge/pull/333 + [status, headers, ::Rack::BodyProxy.new(body)] ensure ActiveSupport::LogSubscriber.flush_all! end