Skip to content

Commit

Permalink
Revert "FEATURE: Prepend Net::HTTP patch instead of class_eval and al…
Browse files Browse the repository at this point in the history
…iasing (#429)"

This reverts commit 89cf094.

Sadly this causes conflicts with at least a couple of popular gems that
have their own patches for `Net::HTTP#request`. The gems apply their
patches by using method aliasing which conflicts with patches applied
using module prepend and causes infinite loop.

#437
Ruby issue: https://bugs.ruby-lang.org/issues/11120
  • Loading branch information
OsamaSayegh committed Mar 14, 2020
1 parent 3cb877b commit 2f321c1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/patches/net_patches.rb
@@ -1,13 +1,16 @@
# frozen_string_literal: true

if (defined?(Net) && defined?(Net::HTTP))
module NetHTTPWithMiniProfiler
def request(request, *args, &block)

Net::HTTP.class_eval do
def request_with_mini_profiler(*args, &block)
request = args[0]
Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do
super
request_without_mini_profiler(*args, &block)
end
end
alias request_without_mini_profiler request
alias request request_with_mini_profiler
end

Net::HTTP.prepend(NetHTTPWithMiniProfiler)
end

0 comments on commit 2f321c1

Please sign in to comment.