Skip to content

Commit

Permalink
The less hacky way to get the stream behaviour working for em-http-re…
Browse files Browse the repository at this point in the history
…quest. Suggested by @mloughran
  • Loading branch information
bblimke committed Jul 9, 2010
1 parent 26cb92f commit 15f888e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -498,6 +498,7 @@ People who submitted patches and new features or suggested improvements. Many th
* Razic
* Steve Tooke
* Nathaniel Bibler
* Martyn Loughran

## Background

Expand Down
12 changes: 7 additions & 5 deletions lib/webmock/http_lib_adapters/em_http_request.rb
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions spec/em_http_request_spec_helper.rb
Expand Up @@ -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
})
Expand Down Expand Up @@ -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.