Skip to content

Commit

Permalink
Merge branch 'master' into em_http_middleware_after_request_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bblimke committed Aug 26, 2012
2 parents 3fb913d + 43098e1 commit f40be82
Show file tree
Hide file tree
Showing 25 changed files with 427 additions and 167 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -7,5 +7,10 @@ rvm:
- jruby-18mode
- rbx-18mode
- rbx-19mode
matrix:
allow_failures:
- rvm: rbx-18mode
- rvm: rbx-19mode
- rvm: jruby-19mode

script: "bundle exec rake && rake em_http_request_0_x_spec"
45 changes: 45 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,50 @@
# Changelog

## 1.8.9

* Fixed problem with caching nil responses when the same HTTPClient instance is used.

Thanks to [Myron Marston](https://github.com/myronmarston)

* Added support for Addressable >= 2.3.0. Addressable 2.3.0 removed support for multiple query value notations and broke backwards compatibility.

https://github.com/sporkmonger/addressable/commit/f51e290b5f68a98293327a7da84eb9e2d5f21c62
https://github.com/sporkmonger/addressable/issues/77


## 1.8.8

* Fixed Net::HTTP adapter so that it returns `nil` for an empty body response.

Thanks to [Myron Marston](https://github.com/myronmarston)

* Gemspec defines compatibility with Addressable ~> 2.2.8, not >= 2.3.0

* Specs compatibility with Typhoeus 0.4.0

Thanks to [Hans Hasselberg](https://github.com/i0rek)

* Handling content types that specify a charset

Thanks to [Kevin Glowacz](https://github.com/kjg)

* Fixed em-http-request adapter to correctly fetch authorization header from a request

Thanks to [Julien Boyer](https://github.com/chatgris)

* Fixing travis-ci image to report master's status

Thanks to [Ryan Schlesinger](https://github.com/ryansch)

* Fixed problem with em-http-request callback triggering if there were other EM::Deferred callbacks registered

Thanks to [Jon Leighton](https://github.com/jonleighton)

* Fixed problem with em-http-request appending the query to the URI a second time, and
the parameters are repeated.

Thanks to [Jon Leighton](https://github.com/jonleighton)

## 1.8.7

* Compatibility with RSpec >= 2.10
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -17,5 +17,5 @@ group :test do
end

platforms :jruby do
gem 'jruby-openssl', '~> 0.7.4.0'
gem 'jruby-openssl', '~> 0.7.7'
end
8 changes: 7 additions & 1 deletion README.md
@@ -1,4 +1,4 @@
WebMock [![Build Status](https://secure.travis-ci.org/bblimke/webmock.png)](http://travis-ci.org/bblimke/webmock) [![Dependency Status](https://gemnasium.com/bblimke/webmock.png)](http://gemnasium.com/bblimke/webmock)
WebMock [![Build Status](https://secure.travis-ci.org/bblimke/webmock.png?branch=master)](http://travis-ci.org/bblimke/webmock) [![Dependency Status](https://gemnasium.com/bblimke/webmock.png)](http://gemnasium.com/bblimke/webmock)
=======

Library for stubbing and setting expectations on HTTP requests in Ruby.
Expand Down Expand Up @@ -707,6 +707,12 @@ People who submitted patches and new features or suggested improvements. Many th
* Eric Oestrich
* erwanlr
* Ben Bleything
* Jon Leighton
* Ryan Schlesinger
* Julien Boyer
* Kevin Glowacz
* Hans Hasselberg
* Andrew France

For a full list of contributors you can visit the
[contributors](https://github.com/bblimke/webmock/contributors) page.
Expand Down
1 change: 1 addition & 0 deletions lib/webmock.rb
Expand Up @@ -8,6 +8,7 @@

require 'webmock/errors'

require 'webmock/util/query_mapper'
require 'webmock/util/uri'
require 'webmock/util/headers'
require 'webmock/util/hash_counter'
Expand Down
94 changes: 30 additions & 64 deletions lib/webmock/http_lib_adapters/curb_adapter.rb
Expand Up @@ -170,117 +170,83 @@ def build_webmock_response
### Mocks of Curl::Easy methods below here.
###

def http_with_webmock(method)
def http(method)
@webmock_method = method
http_without_webmock(method)
super
end
alias_method :http_without_webmock, :http
alias_method :http, :http_with_webmock

%w[ get head delete ].each do |verb|
define_method "http_#{verb}_with_webmock" do
define_method "http_#{verb}" do
@webmock_method = verb
send( "http_#{verb}_without_webmock" )
super()
end

alias_method "http_#{verb}_without_webmock", "http_#{verb}"
alias_method "http_#{verb}", "http_#{verb}_with_webmock"
end

def http_put_with_webmock data = nil
def http_put data = nil
@webmock_method = :put
@put_data = data if data
http_put_without_webmock(data)
super
end
alias_method :http_put_without_webmock, :http_put
alias_method :http_put, :http_put_with_webmock

def http_post_with_webmock *data
def http_post *data
@webmock_method = :post
@post_body = data.join('&') if data && !data.empty?
http_post_without_webmock(*data)
super
end
alias_method :http_post_without_webmock, :http_post
alias_method :http_post, :http_post_with_webmock


def perform_with_webmock
def perform
@webmock_method ||= :get
curb_or_webmock do
perform_without_webmock
end
curb_or_webmock { super }
end
alias :perform_without_webmock :perform
alias :perform :perform_with_webmock

def put_data_with_webmock= data
def put_data= data
@webmock_method = :put
@put_data = data
self.put_data_without_webmock = data
super
end
alias_method :put_data_without_webmock=, :put_data=
alias_method :put_data=, :put_data_with_webmock=

def post_body_with_webmock= data
def post_body= data
@webmock_method = :post
self.post_body_without_webmock = data
super
end
alias_method :post_body_without_webmock=, :post_body=
alias_method :post_body=, :post_body_with_webmock=

def delete_with_webmock= value
def delete= value
@webmock_method = :delete if value
self.delete_without_webmock = value
super
end
alias_method :delete_without_webmock=, :delete=
alias_method :delete=, :delete_with_webmock=

def head_with_webmock= value
def head= value
@webmock_method = :head if value
self.head_without_webmock = value
super
end
alias_method :head_without_webmock=, :head=
alias_method :head=, :head_with_webmock=

def body_str_with_webmock
@body_str || body_str_without_webmock
def body_str
@body_str || super
end
alias :body_str_without_webmock :body_str
alias :body_str :body_str_with_webmock

def response_code_with_webmock
@response_code || response_code_without_webmock
def response_code
@response_code || super
end
alias :response_code_without_webmock :response_code
alias :response_code :response_code_with_webmock

def header_str_with_webmock
@header_str || header_str_without_webmock
def header_str
@header_str || super
end
alias :header_str_without_webmock :header_str
alias :header_str :header_str_with_webmock

def last_effective_url_with_webmock
@last_effective_url || last_effective_url_without_webmock
def last_effective_url
@last_effective_url || super
end
alias :last_effective_url_without_webmock :last_effective_url
alias :last_effective_url :last_effective_url_with_webmock

def content_type_with_webmock
@content_type || content_type_without_webmock
def content_type
@content_type || super
end
alias :content_type_without_webmock :content_type
alias :content_type :content_type_with_webmock

%w[ success failure header body complete progress ].each do |callback|
class_eval <<-METHOD, __FILE__, __LINE__
def on_#{callback}_with_webmock &block
def on_#{callback} &block
@on_#{callback} = block
on_#{callback}_without_webmock &block
super
end
METHOD
alias_method "on_#{callback}_without_webmock", "on_#{callback}"
alias_method "on_#{callback}", "on_#{callback}_with_webmock"
end
end
end
Expand Down
Expand Up @@ -47,7 +47,7 @@ def close_connection
end
end

def send_request_with_webmock(&block)
def send_request(&block)
request_signature = build_request_signature

WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
Expand All @@ -61,7 +61,7 @@ def send_request_with_webmock(&block)
webmock_response.should_timeout ? "WebMock timeout error" : nil)
client
elsif WebMock.net_connect_allowed?(request_signature.uri)
http = send_request_without_webmock(&block)
http = super
http.callback {
if WebMock::CallbackRegistry.any_callbacks?
webmock_response = build_webmock_response(http)
Expand All @@ -76,10 +76,6 @@ def send_request_with_webmock(&block)
end
end

alias_method :send_request_without_webmock, :send_request
alias_method :send_request, :send_request_with_webmock


private

def build_webmock_response(http)
Expand Down
Expand Up @@ -48,7 +48,7 @@ def #{type}(options = {}, &blk)
end

class WebMockHttpConnection < HttpConnection
def webmock_activate_connection(client)
def activate_connection(client)
request_signature = client.request_signature

if client.stubbed_webmock_response
Expand All @@ -65,13 +65,11 @@ def webmock_activate_connection(client)
finalize_request(client)
@conn.set_deferred_status :succeeded
elsif WebMock.net_connect_allowed?(request_signature.uri)
real_activate_connection(client)
super
else
raise WebMock::NetConnectNotAllowedError.new(request_signature)
end
end
alias_method :real_activate_connection, :activate_connection
alias_method :activate_connection, :webmock_activate_connection
end

class WebMockHttpClient < EventMachine::HttpClient
Expand All @@ -92,7 +90,7 @@ def setup(response, uri, error = nil)
end
end

def send_request_with_webmock(head, body)
def send_request(head, body)
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)

if stubbed_webmock_response
Expand All @@ -104,24 +102,23 @@ def send_request_with_webmock(head, body)
}
self
elsif WebMock.net_connect_allowed?(request_signature.uri)
send_request_without_webmock(head, body)
callback {
if WebMock::CallbackRegistry.any_callbacks?
webmock_response = build_webmock_response
WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :em_http_request, :real_request => true},
request_signature,
webmock_response)
end
}
self
super
else
raise WebMock::NetConnectNotAllowedError.new(request_signature)
end
end

alias_method :send_request_without_webmock, :send_request
alias_method :send_request, :send_request_with_webmock
def set_deferred_status(status, *args)
if status == :succeeded && !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
webmock_response = build_webmock_response
WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :em_http_request, :real_request => true},
request_signature,
webmock_response)
end

super
end

def request_signature
@request_signature ||= build_request_signature
Expand Down Expand Up @@ -153,8 +150,8 @@ def build_request_signature
end

method = @req.method
uri = @req.uri
auth = @req.proxy[:authorization] if @req.proxy
uri = @req.uri.clone
auth = @req.headers[:'proxy-authorization']
query = @req.query

if auth
Expand Down
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/excon_adapter.rb
Expand Up @@ -42,7 +42,7 @@ def self.build_request(params)
params = params.dup
method = (params.delete(:method) || :get).to_s.downcase.to_sym
params[:query] = to_query(params[:query]) if params[:query].is_a?(Hash)
uri = Addressable::URI.new(params).to_s
uri = Addressable::URI.new(params).to_s
WebMock::RequestSignature.new method, uri, :body => params[:body], :headers => params[:headers]
end

Expand Down

0 comments on commit f40be82

Please sign in to comment.