Skip to content

Commit

Permalink
Add options and patch verbs to em-synchrony/em-http
Browse files Browse the repository at this point in the history
  • Loading branch information
therabidbanana committed Oct 18, 2012
1 parent a8b6b8b commit fe1a05a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/em-synchrony/em-http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module EventMachine
module HTTPMethods
%w[get head post delete put].each do |type|
%w[get head post delete put patch options].each do |type|
class_eval %[
alias :a#{type} :#{type}
def #{type}(options = {}, &blk)
Expand All @@ -16,7 +16,7 @@ def #{type}(options = {}, &blk)
if conn.error.nil?
conn.callback { f.resume(conn) }
conn.errback { f.resume(conn) }
Fiber.yield
else
conn
Expand Down
8 changes: 6 additions & 2 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
order.push :head if EventMachine::HttpRequest.new(URL).head
order.push :post if EventMachine::HttpRequest.new(URL).delete
order.push :put if EventMachine::HttpRequest.new(URL).put
order.push :options if EventMachine::HttpRequest.new(URL).options
order.push :patch if EventMachine::HttpRequest.new(URL).patch

(now - start.to_f).should be_within(DELAY * order.size * 0.15).of(DELAY * order.size)
order.should == [:get, :post, :head, :post, :put]
order.should == [:get, :post, :head, :post, :put, :options, :patch]

s.stop
EventMachine.stop
Expand All @@ -49,10 +51,12 @@
multi.add :c, EventMachine::HttpRequest.new(URL).ahead
multi.add :d, EventMachine::HttpRequest.new(URL).adelete
multi.add :e, EventMachine::HttpRequest.new(URL).aput
multi.add :f, EventMachine::HttpRequest.new(URL).aoptions
multi.add :g, EventMachine::HttpRequest.new(URL).apatch
res = multi.perform

(now - start.to_f).should be_within(DELAY * 0.15).of(DELAY)
res.responses[:callback].size.should == 5
res.responses[:callback].size.should == 7
res.responses[:errback].size.should == 0

s.stop
Expand Down

0 comments on commit fe1a05a

Please sign in to comment.