Permalink
Browse files

Handle the HTTP status

  • Loading branch information...
carllerche committed Feb 23, 2011
1 parent d88a133 commit 87884409b2ee81d6ed5a64f327bef0816f8e77ba
Showing with 38 additions and 12 deletions.
  1. +9 −0 lib/kirk/client.rb
  2. +8 −12 lib/kirk/client/exchange.rb
  3. +21 −0 spec/kirk/client_spec.rb
View
@@ -20,6 +20,15 @@ def self.group(opts = {}, &blk)
client.group(opts, &blk)
end
+ %w(request head get post put delete).each do |method|
+ class_eval <<-RUBY
+ def self.#{method}(*args, &blk)
+ g = group { |g| g.#{method}(*args, &blk) }
+ g.responses.first
+ end
+ RUBY
+ end
+
def group(opts = {}, &blk)
Group.new(self, opts).tap do |group|
group.start(&blk)
@@ -84,12 +84,11 @@ def onException(ex)
# end
# end
- # def onRequestComplete
- # # p [ :onRequestComplete ]
- # if handler.respond_to?(:on_request_complete)
- # handler.on_request_complete
- # end
- # end
+ def onRequestComplete
+ if handler.respond_to?(:on_request_complete)
+ handler.on_request_complete
+ end
+ end
def onResponseComplete
if handler.respond_to?(:on_response_complete)
@@ -121,12 +120,9 @@ def onResponseHeaderComplete
end
end
- # def onResponseStatus(version, status, reason)
- # # p [ :onResponseStatus ]
- # super
- # response.version = stringify(version)
- # response.status = status
- # end
+ def onResponseStatus(version, status, reason)
+ response.status = status
+ end
# def onRetry
# # p [ :onRetry ]
View
@@ -99,6 +99,27 @@ def on_response_complete(response)
end
end
+ it "sets the response status when it is successful" do
+ start lambda { |env| [ 200, { 'Content-Type' => 'text/plain' }, ['Hello'] ] }
+
+ resp = Kirk::Client.get 'http://localhost:9090/'
+ resp.status.should == 200
+ end
+
+ it "sets the response status when it is 201" do
+ start lambda { |env| [ 201, { 'Content-Type' => 'text/plain' }, ['Hello'] ] }
+
+ resp = Kirk::Client.get 'http://localhost:9090/'
+ resp.status.should == 201
+ end
+
+ it "sets the response status when it is 302" do
+ start lambda { |env| [ 302, { 'Content-Type' => 'text/plain' }, ['Hello'] ] }
+
+ resp = Kirk::Client.get 'http://localhost:9090/'
+ resp.status.should == 302
+ end
+
it "fetches all the headers" do
headers = { 'Content-Type' => 'text/plain', 'X-FooBar' => "zomg" }
start(lambda { |env| [ 200, headers, [ "Hello" ] ] })

0 comments on commit 8788440

Please sign in to comment.