Skip to content

Commit

Permalink
Simplify and optimize header matching a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Nov 4, 2010
1 parent 83e8991 commit f28973a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/typhoeus/hydra_mock.rb
Expand Up @@ -93,17 +93,18 @@ def body_matches?(request)
end

def headers_match?(request)
request_headers = NormalizedHeaderHash.new(request.headers)

if empty_headers?(self.headers)
empty_headers?(request.headers)
empty_headers?(request_headers)
else
return false if empty_headers?(request.headers)
return false if empty_headers?(request_headers)

matches = 0
request.headers.each do |key, value|
matches += 1 if headers.has_key?(key) && header_value_matches?(headers[key], value)
headers.each do |key, value|
return false unless header_value_matches?(value, request_headers[key])
end

matches == self.headers.size
true
end
end

Expand Down

0 comments on commit f28973a

Please sign in to comment.