Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (38 sloc) 1.214 kb
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
1 module WebMock
2
effe928 Refactored request matching code.
Bartosz Blimke authored
3 class RequestSignature
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
4
561c6e1 @bblimke Added headers setter to request signature which normalizes headers befor...
authored
5 attr_accessor :method, :uri, :body
6 attr_reader :headers
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
7
effe928 Refactored request matching code.
Bartosz Blimke authored
8 def initialize(method, uri, options = {})
9 self.method = method
10 self.uri = uri.is_a?(Addressable::URI) ? uri : WebMock::Util::URI.normalize_uri(uri)
11 assign_options(options)
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
12 end
13
effe928 Refactored request matching code.
Bartosz Blimke authored
14 def to_s
15 string = "#{self.method.to_s.upcase}"
16 string << " #{WebMock::Util::URI.strip_default_port_from_uri_string(self.uri.to_s)}"
17 string << " with body '#{body.to_s}'" if body && body.to_s != ''
18 if headers && !headers.empty?
19 string << " with headers #{WebMock::Util::Headers.sorted_headers_string(headers)}"
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
20 end
effe928 Refactored request matching code.
Bartosz Blimke authored
21 string
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
22 end
23
561c6e1 @bblimke Added headers setter to request signature which normalizes headers befor...
authored
24 def headers=(headers)
25 @headers = WebMock::Util::Headers.normalize_headers(headers)
26 end
27
a200077 @bblimke Ensure that two request signatures with the same values are treated as t...
authored
28 def hash
29 self.to_s.hash
30 end
31
32 def eql?(other)
33 self.to_s == other.to_s
34 end
90dd4bc @myronmarston Fix RequestSignature#==.
myronmarston authored
35 alias == eql?
a200077 @bblimke Ensure that two request signatures with the same values are treated as t...
authored
36
037daf5 @bblimke Refactored request snipped logic to allow creating snippets from stubs i...
authored
37 def url_encoded?
38 headers && headers['Content-Type'] == 'application/x-www-form-urlencoded'
39 end
40
effe928 Refactored request matching code.
Bartosz Blimke authored
41 private
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
42
effe928 Refactored request matching code.
Bartosz Blimke authored
43 def assign_options(options)
44 self.body = options[:body] if options.has_key?(:body)
561c6e1 @bblimke Added headers setter to request signature which normalizes headers befor...
authored
45 self.headers = options[:headers] if options.has_key?(:headers)
3097944 @porras "with" now accepts a block
porras authored
46 end
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
47
effe928 Refactored request matching code.
Bartosz Blimke authored
48 end
30ff1e5 Introduced RequestSignature to normalize domain and make code more reada...
Bartosz Blimke authored
49
50 end
Something went wrong with that request. Please try again.