Permalink
Browse files

The less hacky way to get the stream behaviour working for em-http-re…

…quest. Suggested by @mloughran
  • Loading branch information...
1 parent 26cb92f commit 15f888ee91ee386c3ba2879788e325ba4e3c6413 @bblimke committed Jul 9, 2010
Showing with 27 additions and 14 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −0 README.md
  3. +7 −5 lib/webmock/http_lib_adapters/em_http_request.rb
  4. +15 −9 spec/em_http_request_spec_helper.rb
View
@@ -1,5 +1,9 @@
#Changelog
+## 1.3.1
+
+* The less hacky way to get the stream behaviour working for em-http-request. Suggested by Martyn Loughran
+
## 1.3.0
* Added support for [em-http-request](http://github.com/igrigorik/em-http-request)
View
@@ -498,6 +498,7 @@ People who submitted patches and new features or suggested improvements. Many th
* Razic
* Steve Tooke
* Nathaniel Bibler
+* Martyn Loughran
## Background
@@ -11,14 +11,16 @@ def setup(response, uri, error = nil)
on_error(error)
fail(self)
else
- receive_data(response)
- succeed(self)
+ EM.next_tick do
+ receive_data(response)
+ succeed(self)
+ end
end
end
- def stream(&blk)
- blk.call(@response)
- end
+ # def stream(&blk)
+ # blk.call(@response)
+ # end
def unbind
end
@@ -21,17 +21,10 @@ def http_request(method, uri, options = {}, &block)
error = http.errors
failed
}
- headers = {}
- if http.response_header
- http.response_header.each do |k,v|
- v = v.join(", ") if v.is_a?(Array)
- headers[k] = v
- end
- end
- http.callback {
+ http.callback {
response = OpenStruct.new({
:body => http.response,
- :headers => WebMock::Util::Headers.normalize_headers(headers),
+ :headers => WebMock::Util::Headers.normalize_headers(extract_response_headers(http)),
:message => http.response_header.http_reason,
:status => http.response_header.status.to_s
})
@@ -60,5 +53,18 @@ def setup_expectations_for_real_request(options = {})
def http_library
:em_http_request
end
+
+ private
+
+ def extract_response_headers(http)
+ headers = {}
+ if http.response_header
+ http.response_header.each do |k,v|
+ v = v.join(", ") if v.is_a?(Array)
+ headers[k] = v
+ end
+ end
+ headers
+ end
end

0 comments on commit 15f888e

Please sign in to comment.