Permalink
Browse files

Merge branch 'master' into addressable

Conflicts:
	README.md
  • Loading branch information...
2 parents a93db6d + 90c3bb2 commit 64809ffedb1e4f645ae4da5495aa152ff2520610 @maxlinc maxlinc committed Feb 13, 2014
View
@@ -3,13 +3,15 @@ rvm:
- 1.9.2
- 1.9.3
- 2.0.0
+ - 2.1.0
+ - ruby-head
- ree
- - jruby-19mode
- jruby-18mode
- - rbx-18mode
- - rbx-19mode
+ - jruby-19mode
+ - jruby
+ - jruby-head
matrix:
allow_failures:
- - rvm: rbx-18mode
- - rvm: rbx-19mode
- rvm: jruby-18mode
+ - rvm: jruby-head
+ - rvm: ruby-head
View
@@ -1,5 +1,51 @@
# Changelog
+## 1.17.3
+
+* Fixed issue with Rack response removing 'Content-Type' header
+
+ Thanks to [Bo Jeanes](https://github.com/bjeanes) and [Matthew Conway](https://github.com/mattonrails)
+
+## 1.17.2
+
+* Support for chunked responses in Curb
+
+ Thanks to [Zachary Belzer](https://github.com/zbelzer)
+
+* Fixed handling of request body passed as a hash to `Typhoeus.post`
+
+ Thanks to [Mason Chang](https://github.com/changmason) for reporting.
+
+## 1.17.1
+
+* Added missing license statements.
+
+ Thanks to [Praveen Arimbrathodiyil](https://github.com/pravi)
+
+## 1.17.0
+
+* HTTP gem support!
+
+ Thanks to [Aleksey V. Zapparov](https://github.com/ixti)
+
+* Limited Excon gem requirement to version < 0.30 until the compatibility with version > 0.30.0 is fixed.
+
+ Thanks to [Aleksey V. Zapparov](https://github.com/ixti)
+
+* Fixed issue where empty query key caused a `TypeError`
+
+ Thanks to [Jon Rowe](https://github.com/JonRowe)
+
+* Handling Typhoeus `on_headers` and `on_body` params.
+
+ Thanks to [Matt Burke](https://github.com/spraints)
+
+## 1.16.1
+
+* Fixed "NameError: uninitialized constant WebMock::Response::Pathname" issue.
+
+ Thanks to [Alex Stupakow and Karen Wang](https://github.com/stupakov) for the fix.
+
## 1.16.0
* Allow a Pathname to be passed as a Response body
View
@@ -25,6 +25,7 @@ Supported HTTP libraries
* Curb (currently only Curb::Easy)
* Typhoeus (currently only Typhoeus::Hydra)
* Excon
+* HTTP Gem
Supported Ruby Interpreters
---------------------------
@@ -412,6 +413,13 @@ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
Net::HTTP.get('www.example.com', '/') # ===> "def\n"
```
+### Removing unused stubs
+
+```ruby
+stub_get = stub_request(:get, "www.example.com")
+remove_request_stub(stub_get)
+```
+
### Real requests to network can be allowed or disabled
```ruby
@@ -889,6 +897,14 @@ People who submitted patches and new features or suggested improvements. Many th
* Riley Strong
* Tamir Duberstein
* Stefano Uliari
+* Alex Stupakov
+* Karen Wang
+* Matt Burke
+* Jon Rowe
+* Aleksey V. Zapparov
+* Praveen Arimbrathodiyil
+* Bo Jeanes
+* Matthew Conway
* Max Lincoln
For a full list of contributors you can visit the
View
@@ -39,6 +39,7 @@
require 'webmock/http_lib_adapters/http_lib_adapter_registry'
require 'webmock/http_lib_adapters/http_lib_adapter'
require 'webmock/http_lib_adapters/net_http'
+require 'webmock/http_lib_adapters/http_gem_adapter'
require 'webmock/http_lib_adapters/httpclient_adapter'
require 'webmock/http_lib_adapters/patron_adapter'
require 'webmock/http_lib_adapters/curb_adapter'
@@ -125,6 +125,7 @@ def build_curb_response(webmock_response)
end
@content_type = webmock_response.headers["Content-Type"]
+ @transfer_encoding = webmock_response.headers["Transfer-Encoding"]
end
@last_effective_url ||= self.url
@@ -144,7 +145,15 @@ def webmock_follow_location(location)
def invoke_curb_callbacks
@on_progress.call(0.0,1.0,0.0,1.0) if @on_progress
self.header_str.lines.each { |header_line| @on_header.call header_line } if @on_header
- @on_body.call(self.body_str) if @on_body
+ if @on_body
+ if chunked_response?
+ self.body_str.each do |chunk|
+ @on_body.call(chunk)
+ end
+ else
+ @on_body.call(self.body_str)
+ end
+ end
@on_complete.call(self) if @on_complete
case response_code
@@ -155,6 +164,10 @@ def invoke_curb_callbacks
end
end
+ def chunked_response?
+ @transfer_encoding == 'chunked' && self.body_str.respond_to?(:each)
+ end
+
def build_webmock_response
status, headers =
WebMock::HttpLibAdapters::CurbAdapter.parse_header_string(self.header_str)
@@ -0,0 +1,170 @@
+begin
+ require "http"
+rescue LoadError
+ # HTTP gem not found
+end
+
+
+if defined?(HTTP::Client)
+ module WebMock
+ module HttpLibAdapters
+ class HttpGemAdapter < HttpLibAdapter
+
+ adapter_for :http_gem
+
+
+ def self.enable!
+ ::HTTP.enable_webmock!
+ end
+
+
+ def self.disable!
+ ::HTTP.disable_webmock!
+ end
+
+ end
+ end
+ end
+
+
+ module HTTP
+ class Request
+
+ def webmock_signature
+ ::WebMock::RequestSignature.new(method, uri.to_s, {
+ :headers => headers,
+ :body => body
+ })
+ end
+
+ end
+
+
+ class Response
+
+ def to_webmock
+ webmock_response = ::WebMock::Response.new
+
+ webmock_response.status = [status, reason]
+ webmock_response.body = body.to_s
+ webmock_response.headers = headers
+
+ webmock_response
+ end
+
+
+ def self.from_webmock(webmock_response)
+ status = webmock_response.status.first
+ headers = webmock_response.headers || {}
+ body = webmock_response.body
+
+ new(status, "1.1", headers, body)
+ end
+
+ end
+
+
+ class WebMockPerform
+
+ def initialize request, &perform
+ @request = request
+ @perform = perform
+ end
+
+
+ def exec
+ replay || perform || halt
+ end
+
+
+ def request_signature
+ unless @request_signature
+ @request_signature = @request.webmock_signature
+ register_request(@request_signature)
+ end
+
+ @request_signature
+ end
+
+
+ protected
+
+
+ def response_for_request(signature)
+ ::WebMock::StubRegistry.instance.response_for_request(signature)
+ end
+
+
+ def register_request(signature)
+ ::WebMock::RequestRegistry.instance.requested_signatures.put(signature)
+ end
+
+
+ def replay
+ webmock_response = response_for_request(request_signature)
+
+ return unless webmock_response
+
+ raise Errno::ETIMEDOUT if webmock_response.should_timeout
+ webmock_response.raise_error_if_any
+
+ invoke_callbacks(webmock_response, :real_request => false)
+ ::HTTP::Response.from_webmock webmock_response
+ end
+
+
+ def perform
+ return unless ::WebMock.net_connect_allowed?(request_signature.uri)
+ response = @perform.call
+ invoke_callbacks(response.to_webmock, :real_request => true)
+ response
+ end
+
+
+ def halt
+ raise ::WebMock::NetConnectNotAllowedError.new request_signature
+ end
+
+
+ def invoke_callbacks webmock_response, options = {}
+ ::WebMock::CallbackRegistry.invoke_callbacks(
+ options.merge({ :lib => :http_gem }),
+ request_signature,
+ webmock_response
+ )
+ end
+
+ end
+
+
+ class Client
+
+ alias :__perform__ :perform
+
+ def perform request, options
+ return __perform__(request, options) unless ::HTTP.webmock_enabled?
+ WebMockPerform.new(request) { __perform__(request, options) }.exec
+ end
+
+ end
+
+
+ class << self
+
+ def enable_webmock!
+ @webmock_enabled = true
+ end
+
+
+ def disable_webmock!
+ @webmock_enabled = false
+ end
+
+
+ def webmock_enabled?
+ @webmock_enabled
+ end
+
+ end
+ end
+end
@@ -59,6 +59,10 @@ def self.build_request_signature(req)
body = req.options[:body]
+ if body.is_a?(Hash)
+ body = WebMock::Util::QueryMapper.values_to_query(body)
+ end
+
request_signature = WebMock::RequestSignature.new(
req.options[:method] || :get,
uri.to_s,
@@ -143,6 +147,13 @@ def self.request_hash(request_signature)
if webmock_response = ::WebMock::StubRegistry.instance.response_for_request(request_signature)
# ::WebMock::HttpLibAdapters::TyphoeusAdapter.stub_typhoeus(request_signature, webmock_response, self)
response = ::WebMock::HttpLibAdapters::TyphoeusAdapter.generate_typhoeus_response(request_signature, webmock_response)
+ if request.respond_to?(:on_headers)
+ request.execute_headers_callbacks(response)
+ end
+ if request.respond_to?(:streaming?) && request.streaming?
+ response.options[:response_body] = ""
+ request.on_body.each { |callback| callback.call(webmock_response.body, response) }
+ end
request.finish(response)
webmock_response.raise_error_if_any
res = false
@@ -25,7 +25,7 @@ def body_from_rack_response(response)
def build_rack_env(request)
uri = request.uri
- headers = request.headers || {}
+ headers = (request.headers || {}).dup
body = request.body || ''
env = {
View
@@ -1,3 +1,5 @@
+require "pathname"
+
#compatibility with Ruby 1.9.2 preview1 to allow reading raw responses
class StringIO
alias_method :read_nonblock, :sysread
View
@@ -1,5 +1,10 @@
# This is a copy of https://github.com/jnunemaker/crack/blob/master/lib/crack/json.rb
# with date parsing removed
+# Copyright (c) 2004-2008 David Heinemeier Hansson
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
module WebMock
module Util
class JSON
@@ -131,8 +131,8 @@ def self.values_to_query(new_query_values)
end
new_query_values = new_query_values.to_hash
new_query_values = new_query_values.map do |key, value|
- key = key.to_s if key.kind_of?(Symbol)
- [key, value]
+ key = key.to_s if key.kind_of?(Symbol) || key.nil?
+ [key.to_s, value]
end
# Useful default for OAuth and caching.
# Only to be used for non-Array inputs. Arrays should preserve order.
Oops, something went wrong.

0 comments on commit 64809ff

Please sign in to comment.