Skip to content

Commit

Permalink
Allow filtering based on net_http_connect_on_start
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed May 22, 2022
1 parent 00e42e1 commit b1b5a2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/webmock/http_lib_adapters/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def request(request, body = nil, &block)
after_request.call(response)
}
if started?
if WebMock::Config.instance.net_http_connect_on_start
if WebMock.net_http_connect_on_start?(request_signature.uri)
super_with_after_request.call
else
start_with_connect_without_finish {
Expand Down Expand Up @@ -144,7 +144,9 @@ def start_with_connect_without_finish # :yield: http
alias_method :start_with_connect, :start

def start(&block)
if WebMock::Config.instance.net_http_connect_on_start
uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self))

if WebMock.net_http_connect_on_start?(uri)
super(&block)
else
start_without_connect(&block)
Expand Down
4 changes: 4 additions & 0 deletions lib/webmock/webmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def self.net_connect_allowed?(uri = nil)
Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
end

def self.net_http_connect_on_start?(uri)
Config.instance.net_http_connect_on_start
end

def self.net_connect_explicit_allowed?(allowed, uri=nil)
case allowed
when Array
Expand Down

0 comments on commit b1b5a2e

Please sign in to comment.