Skip to content
Snippets Groups Projects
Unverified Commit 833d9c2f authored by James Tucker's avatar James Tucker Committed by GitHub
Browse files

Improve performance by avoiding method cache busts (#19957)

Switch to monkey-patching http.rb rather than a runtime extend of each
response, so as to avoid busting the global method cache. A guard is
included that will provide developer feedback in development and test
environments should the monkey patch ever collide.
parent 9f4930ec
No related branches found
No related tags found
No related merge requests found
...@@ -62,8 +62,6 @@ class Request ...@@ -62,8 +62,6 @@ class Request
end end
begin begin
response = response.extend(ClientLimit)
# If we are using a persistent connection, we have to # If we are using a persistent connection, we have to
# read every response to be able to move forward at all. # read every response to be able to move forward at all.
# However, simply calling #to_s or #flush may not be safe, # However, simply calling #to_s or #flush may not be safe,
...@@ -181,6 +179,14 @@ class Request ...@@ -181,6 +179,14 @@ class Request
end end
end end
if ::HTTP::Response.methods.include?(:body_with_limit) && !Rails.env.production?
abort 'HTTP::Response#body_with_limit is already defined, the monkey patch will not be applied'
else
class ::HTTP::Response
include Request::ClientLimit
end
end
class Socket < TCPSocket class Socket < TCPSocket
class << self class << self
def open(host, *args) def open(host, *args)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment