webmock 1.24.6 → 2.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -9
  3. data/CHANGELOG.md +37 -8
  4. data/Gemfile +1 -5
  5. data/README.md +22 -51
  6. data/Rakefile +0 -23
  7. data/lib/webmock.rb +0 -12
  8. data/lib/webmock/cucumber.rb +2 -0
  9. data/lib/webmock/http_lib_adapters/curb_adapter.rb +9 -3
  10. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +220 -9
  11. data/lib/webmock/http_lib_adapters/excon_adapter.rb +2 -0
  12. data/lib/webmock/http_lib_adapters/http_rb/response.rb +1 -1
  13. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +0 -38
  14. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +6 -2
  15. data/lib/webmock/http_lib_adapters/net_http.rb +2 -10
  16. data/lib/webmock/http_lib_adapters/patron_adapter.rb +7 -3
  17. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +6 -2
  18. data/lib/webmock/minitest.rb +2 -0
  19. data/lib/webmock/request_pattern.rb +16 -1
  20. data/lib/webmock/response.rb +0 -7
  21. data/lib/webmock/rspec.rb +2 -0
  22. data/lib/webmock/test_unit.rb +2 -0
  23. data/lib/webmock/util/headers.rb +4 -0
  24. data/lib/webmock/util/query_mapper.rb +1 -2
  25. data/lib/webmock/version.rb +1 -1
  26. data/lib/webmock/webmock.rb +0 -2
  27. data/spec/acceptance/curb/curb_spec_helper.rb +6 -3
  28. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +4 -1
  29. data/spec/acceptance/excon/excon_spec_helper.rb +9 -3
  30. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +7 -1
  31. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +5 -2
  32. data/spec/acceptance/manticore/manticore_spec_helper.rb +5 -1
  33. data/spec/acceptance/net_http/net_http_spec.rb +2 -2
  34. data/spec/acceptance/net_http/net_http_spec_helper.rb +4 -1
  35. data/spec/acceptance/patron/patron_spec_helper.rb +6 -3
  36. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +2 -2
  37. data/spec/acceptance/shared/request_expectations.rb +64 -7
  38. data/spec/acceptance/shared/stubbing_requests.rb +51 -1
  39. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +11 -8
  40. data/spec/spec_helper.rb +0 -4
  41. data/spec/unit/request_pattern_spec.rb +1 -1
  42. data/spec/unit/util/query_mapper_spec.rb +0 -16
  43. data/webmock.gemspec +5 -7
  44. metadata +187 -236
  45. data/Appraisals +0 -3
  46. data/gemfiles/ruby_1_8.gemfile +0 -21
  47. data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_0_x.rb +0 -147
  48. data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb +0 -228
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ff6dc7d940f08ae334e0220100267ab6a41a58e4
4
+ data.tar.gz: 35dd3369af56b08b38fdf59f943c56b9552eb31e
5
+ SHA512:
6
+ metadata.gz: f8448b8a8a176d912a448912133bc68b0edfa37c136235821f938153a7ef421ac2a2218996de115676469c781668a1b70abf0740140b2a3751419b7b267762b0
7
+ data.tar.gz: 389edffa68682edbf92649d0346073193abf5dd9d918249a3c6d381eecb5ae2954b01a739d803b467bbc65bf1438a82b30bb322c9796a93010b881ec28322dd1
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.0
@@ -14,16 +13,8 @@ rvm:
14
13
  - jruby
15
14
  - jruby-head
16
15
  matrix:
17
- include:
18
- - rvm: 1.8.7
19
- gemfile: gemfiles/ruby_1_8.gemfile
20
- - rvm: ree
21
- gemfile: gemfiles/ruby_1_8.gemfile
22
- - rvm: jruby-18mode
23
- gemfile: gemfiles/ruby_1_8.gemfile
24
16
  allow_failures:
25
17
  - rvm: jruby-9.0.0.0
26
- - rvm: jruby-18mode
27
18
  - rvm: jruby-head
28
19
  - rvm: ruby-head
29
20
  - rvm: rbx-2
@@ -1,19 +1,43 @@
1
1
  # Changelog
2
2
 
3
- ## 1.24.6
3
+ ## 2.0.0
4
4
 
5
- * Fixed issue with RUBY_VERSION comparison using old RubyGems.
5
+ * require 'webmock' does not enable WebMock anymore. `gem 'webmock'` can be now safely added to the Gemfile without modifying http clients. Call `WebMock.enable!` to enable it.
6
6
 
7
- Thanks to [Chris Griego](https://github.com/cgriego).
7
+ Please note that `require 'webmock/rspec'`, `require 'webmock/test_unit'`, `require 'webmock/minitest'` and `require 'webmock/cucumber'` still do enable WebMock.
8
8
 
9
- * Support for http.rb >= 2.0.0
9
+ * Dropped support for Ruby < 1.9.3
10
10
 
11
- ## 1.24.4
11
+ * Dropped support for em-http-request < 1.0.0
12
12
 
13
- * Fixed the issue with parsing query to a hash with nested array i.e. `a[][b][]=one&a[][c][]=two`
13
+ * WebMock 2.0 does not match basic auth credentials in the userinfo part of the url, with credentials passed in `Authorization: Basic ...` header.
14
+ It now treats the Authorization header and credentials in userinfo in the url as completely separate attributes of the request.
15
+
16
+ The following stub declaration, which used to work in WebMock 1.x, is not going to work anymore
17
+
18
+ stub_request(:get, "user:pass@www.example.com")
19
+
20
+ Net::HTTP.start('www.example.com') do |http|
21
+ req = Net::HTTP::Get.new('/')
22
+ req.basic_auth 'user', 'pass'
23
+ http.request(req)
24
+ end # ===> Failure
25
+
26
+ In order to stub a request with basic authentication credentials provided in the Authorization header, please use the following code:
27
+
28
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
29
+
30
+ or
31
+
32
+ stub_request(:get, "www.example.com").
33
+ with(headers: 'Authorization' => "Basic #{ Base64.encode64('user:pass').chomp}")
34
+
35
+ In order to stub a request with basic authentication credentials provided in the url please use the following code:
36
+
37
+ stub_request(:get, "user:pass@www.example.com")
38
+
39
+ RestClient.get('user:pass@www.example.com') # ===> Success
14
40
 
15
- Thanks to [Tim Diggins](https://github.com/timdiggins) for reporting the issue.
16
- Thanks to [Cedric Pimenta](https://github.com/cedricpim) for finding the solution.
17
41
 
18
42
  ## 1.24.3
19
43
 
@@ -21,6 +45,11 @@
21
45
 
22
46
  Thanks to [Alex Kestner](https://github.com/akestner)
23
47
 
48
+ * Fixed the issue with parsing query to a hash with nested array i.e. `a[][b][]=one&a[][c][]=two`
49
+
50
+ Thanks to [Tim Diggins](https://github.com/timdiggins) for reporting the issue.
51
+ Thanks to [Cedric Pimenta](https://github.com/cedricpim) for finding the solution.
52
+
24
53
  * Added a clear message on an attept to match a multipart encoded request body.
25
54
  WebMock does't support requests with multipart body... yet.
26
55
 
data/Gemfile CHANGED
@@ -1,13 +1,9 @@
1
1
  source 'http://rubygems.org/'
2
2
 
3
3
  gemspec
4
- if ENV["EM_HTTP_REQUEST_0_X"]
5
- gem 'em-http-request', '~> 0.3.0'
6
- end
7
4
 
8
5
  group :development do
9
- gem 'rake', '~> 10.5.0' if RUBY_VERSION < '1.9.3'
10
- gem 'rake' if RUBY_VERSION >= '1.9.3'
6
+ gem 'rake'
11
7
  end
12
8
 
13
9
  group :test do
data/README.md CHANGED
@@ -32,15 +32,11 @@ Supported HTTP libraries
32
32
  Supported Ruby Interpreters
33
33
  ---------------------------
34
34
 
35
- * MRI 1.8.7
36
- * MRI 1.9.1
37
- * MRI 1.9.2
38
35
  * MRI 1.9.3
39
36
  * MRI 2.0.0
40
37
  * MRI 2.1
41
38
  * MRI 2.2
42
39
  * MRI 2.3
43
- * REE 1.8.7
44
40
  * JRuby
45
41
  * Rubinius
46
42
 
@@ -54,6 +50,10 @@ Supported Ruby Interpreters
54
50
  cd webmock
55
51
  rake install
56
52
 
53
+ ## Upgrading from v1.x to v2.x
54
+
55
+ WebMock 2.x has changed somewhat since version 1.x. Changes are listed in [CHANGELOG.md](CHANGELOG.md)
56
+
57
57
  ### Test::Unit
58
58
 
59
59
  Add the following code to `test/test_helper.rb`
@@ -93,11 +93,9 @@ You can also use WebMock outside a test framework:
93
93
  ```ruby
94
94
  require 'webmock'
95
95
  include WebMock::API
96
- ```
97
-
98
- ### Automatically enabled
99
96
 
100
- `require 'webmock'` loads the library AND enables `WebMock`. Add `WebMock.disable!` after loading the gem to disable this behavior.
97
+ WebMock.enable!
98
+ ```
101
99
 
102
100
  ## Examples
103
101
 
@@ -205,10 +203,13 @@ stub_request(:post, "www.example.com").with { |request| request.body == "abc" }
205
203
  RestClient.post('www.example.com', 'abc') # ===> Success
206
204
  ```
207
205
 
208
- ### Request with basic authentication
206
+ ### Request with basic authentication header
209
207
 
210
208
  ```ruby
211
- stub_request(:get, "user:pass@www.example.com")
209
+ stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass'])
210
+ # or
211
+ # stub_request(:get, "www.example.com").
212
+ # with(headers: 'Authorization' => "Basic #{ Base64.encode64('user:pass').chomp}")
212
213
 
213
214
  Net::HTTP.start('www.example.com') do |http|
214
215
  req = Net::HTTP::Get.new('/')
@@ -217,6 +218,16 @@ Net::HTTP.start('www.example.com') do |http|
217
218
  end # ===> Success
218
219
  ```
219
220
 
221
+ ##### Important! Since version 2.0.0, WebMock does not match credentials provided in Authorization header and credentials provided in the userinfo of a url. I.e. `stub_request(:get, "user:pass@www.example.com")` does not match a request with credentials provided in the Athoriation header.
222
+
223
+ ### Request with basic authentication in the url
224
+
225
+ ```ruby
226
+ stub_request(:get, "user:pass@www.example.com")
227
+
228
+ RestClient.get('user:pass@www.example.com') # ===> Success
229
+ ```
230
+
220
231
  ### Matching uris using regular expressions
221
232
 
222
233
  ```ruby
@@ -739,7 +750,7 @@ I.e all the following representations of the URI are equal:
739
750
  "http://www.example.com:80/"
740
751
  ```
741
752
 
742
- The following URIs with basic authentication are also equal for WebMock
753
+ The following URIs with userinfo are also equal for WebMock
743
754
 
744
755
  ```ruby
745
756
  "a b:pass@www.example.com"
@@ -842,45 +853,6 @@ In order to work on Webmock you first need to fork and clone the repo.
842
853
  Please do any work on a dedicated branch and rebase against master
843
854
  before sending a pull request.
844
855
 
845
- #### Running Tests
846
-
847
- We use RVM in order to test WebMock against 1.8.6, REE, 1.8.7, 1.9.2 and
848
- jRuby. You can get RVM setup for WebMock development using the
849
- following commands (if you don't have these version of Ruby installed
850
- use `rvm install` to install each of them).
851
-
852
- rvm use --create 1.8.6@webmock
853
- gem install jeweler bundler
854
- bundle install
855
-
856
- rvm use --create ree@webmock
857
- gem install jeweler bundler
858
- bundle install
859
-
860
- rvm use --create 1.8.7@webmock
861
- gem install jeweler bundler
862
- bundle install
863
-
864
- rvm use --create 1.9.2@webmock
865
- gem install jeweler bundler
866
- bundle install
867
-
868
- rvm use --create jruby@webmock
869
- gem install jeweler bundler
870
- bundle install
871
-
872
- These commands will create a gemset named WebMock for each of the
873
- supported versions of Ruby and `bundle install` all dependencies.
874
-
875
- With the supported versions of Ruby installed RVM will run specs across
876
- all version with just one command.
877
-
878
- bundle exec rvm 1.8.6@webmock,ree@webmock,1.8.7@webmock,1.9.2@webmock,jruby@webmock rspec spec/**/*_spec.rb
879
-
880
- This command is wrapped up in to a rake task and can be invoked like so:
881
-
882
- rake rvm:specs
883
-
884
856
  ## Credits
885
857
 
886
858
  The initial lines of this project were written during New Bamboo [Hack Day](http://blog.new-bamboo.co.uk/2009/11/13/hackday-results)
@@ -1043,7 +1015,6 @@ People who submitted patches and new features or suggested improvements. Many th
1043
1015
  * Manfred Stienstra
1044
1016
  * Tim Diggins
1045
1017
  * Gabriel Chaney
1046
- * Chris Griego
1047
1018
 
1048
1019
  For a full list of contributors you can visit the
1049
1020
  [contributors](https://github.com/bblimke/webmock/contributors) page.
data/Rakefile CHANGED
@@ -3,17 +3,6 @@
3
3
  require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- namespace :rvm do
7
- desc 'Run specs against 1.8.6, REE, 1.8.7, 1.9.2 and jRuby'
8
- task :specs do
9
- # JCF: I'd love to be able to use RVM's `rvm {rubies} specs` command but
10
- # the require tests in spec/other_net_http_libs_spec.rb break when doing
11
- # so.
12
- spec_files = Dir[File.dirname(__FILE__) + '/spec/**/*_spec.rb'].join(' ')
13
- sh "rvm 1.8.6@webmock,ree@webmock,1.8.7@webmock,1.9.2@webmock,jruby@webmock exec rspec #{spec_files}"
14
- end
15
- end
16
-
17
6
  require "rspec/core/rake_task"
18
7
  RSpec::Core::RakeTask.new(:spec) do |t|
19
8
  t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
@@ -25,11 +14,6 @@ RSpec::Core::RakeTask.new(:spec_http_without_webmock) do |t|
25
14
  t.pattern = 'spec/acceptance/net_http/real_net_http_spec.rb'
26
15
  end
27
16
 
28
-
29
- task :em_http_request_0_x_spec do
30
- sh "EM_HTTP_REQUEST_0_X=true bundle install && EM_HTTP_REQUEST_0_X=true bundle exec rspec spec/acceptance/em_http_request/em_http_request_spec.rb" if RUBY_VERSION <= "1.8.7"
31
- end
32
-
33
17
  require 'rake/testtask'
34
18
  Rake::TestTask.new(:test) do |test|
35
19
  test.test_files = FileList["test/**/*.rb"].exclude("test/test_helper.rb")
@@ -43,11 +27,4 @@ Rake::TestTask.new(:minitest) do |test|
43
27
  test.warning = false
44
28
  end
45
29
 
46
-
47
30
  task :default => [:spec, :spec_http_without_webmock, :test, :minitest]
48
-
49
- task :require_ruby_18 do
50
- raise "This must be run on Ruby 1.8" unless RUBY_VERSION =~ /^1\.8/
51
- end
52
-
53
- task :release => [:require_ruby_18]
@@ -52,15 +52,3 @@ require 'webmock/http_lib_adapters/excon_adapter'
52
52
  require 'webmock/http_lib_adapters/manticore_adapter'
53
53
 
54
54
  require 'webmock/webmock'
55
-
56
- if RUBY_VERSION <= "1.8.7" && Addressable::VERSION::STRING >= "2.4.0"
57
- raise StandardError,
58
- <<-ERR
59
- \n\e[31m
60
- Addressable dropped support for Ruby 1.8.7 on version 2.4.0,
61
-
62
- please add the following to your Gemfile to be able to use WebMock:
63
-
64
- gem 'addressable', '< 2.4.0'\e[0m\n
65
- ERR
66
- end
@@ -1,6 +1,8 @@
1
1
  require 'webmock'
2
2
  require 'webmock/rspec/matchers'
3
3
 
4
+ WebMock.enable!
5
+
4
6
  World(WebMock::API, WebMock::Matchers)
5
7
 
6
8
  After do
@@ -84,8 +84,6 @@ if defined?(Curl)
84
84
 
85
85
  uri = WebMock::Util::URI.heuristic_parse(self.url)
86
86
  uri.path = uri.normalized_path.gsub("[^:]//","/")
87
- uri.user = self.username
88
- uri.password = self.password
89
87
 
90
88
  request_body = case method
91
89
  when :post
@@ -100,11 +98,19 @@ if defined?(Curl)
100
98
  method,
101
99
  uri.to_s,
102
100
  :body => request_body,
103
- :headers => self.headers
101
+ :headers => self.headers.merge(basic_auth_headers)
104
102
  )
105
103
  request_signature
106
104
  end
107
105
 
106
+ def basic_auth_headers
107
+ if self.username
108
+ {'Authorization' => WebMock::Util::Headers.basic_auth_header(self.username, self.password)}
109
+ else
110
+ {}
111
+ end
112
+ end
113
+
108
114
  def build_curb_response(webmock_response)
109
115
  raise Curl::Err::TimeoutError if webmock_response.should_timeout
110
116
  webmock_response.raise_error_if_any
@@ -1,11 +1,222 @@
1
- begin
2
- require 'em-http-request'
3
- rescue LoadError
4
- # em-http-request not found
5
- end
1
+ if defined?(EventMachine::HttpClient)
2
+ module WebMock
3
+ module HttpLibAdapters
4
+ class EmHttpRequestAdapter < HttpLibAdapter
5
+ adapter_for :em_http_request
6
+
7
+ OriginalHttpClient = EventMachine::HttpClient unless const_defined?(:OriginalHttpClient)
8
+ OriginalHttpConnection = EventMachine::HttpConnection unless const_defined?(:OriginalHttpConnection)
9
+
10
+ def self.enable!
11
+ EventMachine.send(:remove_const, :HttpConnection)
12
+ EventMachine.send(:const_set, :HttpConnection, EventMachine::WebMockHttpConnection)
13
+ EventMachine.send(:remove_const, :HttpClient)
14
+ EventMachine.send(:const_set, :HttpClient, EventMachine::WebMockHttpClient)
15
+ end
16
+
17
+ def self.disable!
18
+ EventMachine.send(:remove_const, :HttpConnection)
19
+ EventMachine.send(:const_set, :HttpConnection, OriginalHttpConnection)
20
+ EventMachine.send(:remove_const, :HttpClient)
21
+ EventMachine.send(:const_set, :HttpClient, OriginalHttpClient)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ module EventMachine
28
+ if defined?(Synchrony) && HTTPMethods.instance_methods.include?(:aget)
29
+ # have to make the callbacks fire on the next tick in order
30
+ # to avoid the dreaded "double resume" exception
31
+ module HTTPMethods
32
+ %w[get head post delete put].each do |type|
33
+ class_eval %[
34
+ def #{type}(options = {}, &blk)
35
+ f = Fiber.current
36
+
37
+ conn = setup_request(:#{type}, options, &blk)
38
+ conn.callback { EM.next_tick { f.resume(conn) } }
39
+ conn.errback { EM.next_tick { f.resume(conn) } }
40
+
41
+ Fiber.yield
42
+ end
43
+ ]
44
+ end
45
+ end
46
+ end
47
+
48
+ class WebMockHttpConnection < HttpConnection
49
+ def activate_connection(client)
50
+ request_signature = client.request_signature
51
+
52
+ if client.stubbed_webmock_response
53
+ conn = HttpStubConnection.new rand(10000)
54
+ post_init
55
+
56
+ @deferred = false
57
+ @conn = conn
58
+
59
+ conn.parent = self
60
+ conn.pending_connect_timeout = @connopts.connect_timeout
61
+ conn.comm_inactivity_timeout = @connopts.inactivity_timeout
62
+
63
+ finalize_request(client)
64
+ @conn.set_deferred_status :succeeded
65
+ elsif WebMock.net_connect_allowed?(request_signature.uri)
66
+ super
67
+ else
68
+ raise WebMock::NetConnectNotAllowedError.new(request_signature)
69
+ end
70
+ end
71
+
72
+ def drop_client
73
+ @clients.shift
74
+ end
75
+ end
76
+
77
+ class WebMockHttpClient < EventMachine::HttpClient
78
+ include HttpEncoding
79
+
80
+ def uri
81
+ @req.uri
82
+ end
83
+
84
+ def setup(response, uri, error = nil)
85
+ @last_effective_url = @uri = uri
86
+ if error
87
+ on_error(error)
88
+ @conn.drop_client
89
+ fail(self)
90
+ else
91
+ @conn.receive_data(response)
92
+ succeed(self)
93
+ end
94
+ end
95
+
96
+ def send_request(head, body)
97
+ WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
98
+
99
+ if stubbed_webmock_response
100
+ WebMock::CallbackRegistry.invoke_callbacks({:lib => :em_http_request}, request_signature, stubbed_webmock_response)
101
+ @uri ||= nil
102
+ EM.next_tick {
103
+ setup(make_raw_response(stubbed_webmock_response), @uri,
104
+ stubbed_webmock_response.should_timeout ? "WebMock timeout error" : nil)
105
+ }
106
+ self
107
+ elsif WebMock.net_connect_allowed?(request_signature.uri)
108
+ super
109
+ else
110
+ raise WebMock::NetConnectNotAllowedError.new(request_signature)
111
+ end
112
+ end
113
+
114
+ def unbind(reason = nil)
115
+ if !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
116
+ webmock_response = build_webmock_response
117
+ WebMock::CallbackRegistry.invoke_callbacks(
118
+ {:lib => :em_http_request, :real_request => true},
119
+ request_signature,
120
+ webmock_response)
121
+ end
122
+ @request_signature = nil
123
+ remove_instance_variable(:@stubbed_webmock_response)
124
+
125
+ super
126
+ end
127
+
128
+ def request_signature
129
+ @request_signature ||= build_request_signature
130
+ end
131
+
132
+ def stubbed_webmock_response
133
+ unless defined?(@stubbed_webmock_response)
134
+ @stubbed_webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
135
+ end
136
+
137
+ @stubbed_webmock_response
138
+ end
139
+
140
+ def get_response_cookie(name)
141
+ name = name.to_s
142
+
143
+ raw_cookie = response_header.cookie
144
+ raw_cookie = [raw_cookie] if raw_cookie.is_a? String
145
+
146
+ cookie = raw_cookie.select { |c| c.start_with? name }.first
147
+ cookie and cookie.split('=', 2)[1]
148
+ end
149
+
150
+ private
151
+
152
+ def build_webmock_response
153
+ webmock_response = WebMock::Response.new
154
+ webmock_response.status = [response_header.status, response_header.http_reason]
155
+ webmock_response.headers = response_header
156
+ webmock_response.body = response
157
+ webmock_response
158
+ end
159
+
160
+ def build_request_signature
161
+ headers, body = @req.headers, @req.body
162
+
163
+ @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
164
+ headers, body = m.request(self, headers, body)
165
+ end
166
+
167
+ method = @req.method
168
+ uri = @req.uri.clone
169
+ query = @req.query
170
+
171
+ uri.query = encode_query(@req.uri, query).slice(/\?(.*)/, 1)
172
+
173
+ body = form_encode_body(body) if body.is_a?(Hash)
174
+
175
+ headers = @req.headers
176
+
177
+ if headers['authorization']
178
+ headers['Authorization'] = WebMock::Util::Headers.basic_auth_header(headers.delete('authorization'))
179
+ end
180
+
181
+ WebMock::RequestSignature.new(
182
+ method.downcase.to_sym,
183
+ uri.to_s,
184
+ :body => body || (@req.file && File.read(@req.file)),
185
+ :headers => headers
186
+ )
187
+ end
188
+
189
+ def make_raw_response(response)
190
+ response.raise_error_if_any
191
+
192
+ status, headers, body = response.status, response.headers, response.body
193
+ headers ||= {}
194
+
195
+ response_string = []
196
+ response_string << "HTTP/1.1 #{status[0]} #{status[1]}"
197
+
198
+ headers["Content-Length"] = body.bytesize unless headers["Content-Length"]
199
+ headers.each do |header, value|
200
+ if header =~ /set-cookie/i
201
+ [value].flatten.each do |cookie|
202
+ response_string << "#{header}: #{cookie}"
203
+ end
204
+ else
205
+ value = value.join(", ") if value.is_a?(Array)
206
+
207
+ # WebMock's internal processing will not handle the body
208
+ # correctly if the header indicates that it is chunked, unless
209
+ # we also create all the chunks.
210
+ # It's far easier just to remove the header.
211
+ next if header =~ /transfer-encoding/i && value =~/chunked/i
212
+
213
+ response_string << "#{header}: #{value}"
214
+ end
215
+ end if headers
6
216
 
7
- if defined?(EventMachine::HttpConnection)
8
- require File.expand_path(File.dirname(__FILE__) + '/em_http_request/em_http_request_1_x')
9
- else
10
- require File.expand_path(File.dirname(__FILE__) + '/em_http_request/em_http_request_0_x')
217
+ response_string << "" << body
218
+ response_string.join("\n")
219
+ end
220
+ end
221
+ end
11
222
  end