Skip to content

Commit

Permalink
added support for DELETE and PUT requests
Browse files Browse the repository at this point in the history
  • Loading branch information
crohr committed Nov 19, 2009
1 parent 2ab4503 commit 61d0327
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/em-http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def initialize(host, headers = {})

def get options = {}; send_request(:get, options); end
def head options = {}; send_request(:head, options); end
def delete options = {}; send_request(:delete, options); end
def put options = {}; send_request(:put, options); end
def post options = {}; send_request(:post, options); end

protected
Expand Down
8 changes: 7 additions & 1 deletion test/stallion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ def self.call(env)

elsif stable.request.head?
stable.response.status = 200


elsif stable.request.delete?
stable.response.status = 200

elsif stable.request.put?
stable.response.write stable.request.body.read

elsif stable.request.post?
if stable.request.path_info == '/echo_content_type'
stable.response.write stable.request.env["CONTENT_TYPE"]
Expand Down
29 changes: 29 additions & 0 deletions test/test_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ def failed
}
}
end

# should be no different than a GET
it "should perform successfull DELETE with a URI passed as argument" do
EventMachine.run {
uri = URI.parse('http://127.0.0.1:8080/')
http = EventMachine::HttpRequest.new(uri).delete

http.errback { failed }
http.callback {
http.response_header.status.should == 200
http.response.should == ""
EventMachine.stop
}
}
end

it "should return 404 on invalid path" do
EventMachine.run {
Expand Down Expand Up @@ -134,6 +149,20 @@ def failed
}
end

# should be no different than a POST
it "should perform successfull PUT" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/').put :body => "data"

http.errback { failed }
http.callback {
http.response_header.status.should == 200
http.response.should match(/data/)
EventMachine.stop
}
}
end

it "should perform successfull POST" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/').post :body => "data"
Expand Down

0 comments on commit 61d0327

Please sign in to comment.