Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Net::HTTP patch optional by ENV variable
- Loading branch information
1 parent
5d07da7
commit d3fbf79
Showing
2 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
if (defined?(Net) && defined?(Net::HTTP)) | ||
|
||
if defined?(Rack::MINI_PROFILER_PREPEND_NET_HTTP_PATCH) | ||
module NetHTTPWithMiniProfiler | ||
def request(request, *args, &block) | ||
Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do | ||
super | ||
if ENV['RACK_MINI_PROFILER_PATCH_NET_HTTP'] != 'false' | ||
if (defined?(Net) && defined?(Net::HTTP)) | ||
if defined?(Rack::MINI_PROFILER_PREPEND_NET_HTTP_PATCH) | ||
module NetHTTPWithMiniProfiler | ||
def request(request, *args, &block) | ||
Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do | ||
super | ||
end | ||
end | ||
end | ||
end | ||
Net::HTTP.prepend(NetHTTPWithMiniProfiler) | ||
else | ||
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 | ||
request_without_mini_profiler(*args, &block) | ||
Net::HTTP.prepend(NetHTTPWithMiniProfiler) | ||
else | ||
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 | ||
request_without_mini_profiler(*args, &block) | ||
end | ||
end | ||
alias request_without_mini_profiler request | ||
alias request request_with_mini_profiler | ||
end | ||
alias request_without_mini_profiler request | ||
alias request request_with_mini_profiler | ||
end | ||
end | ||
end |