Permalink
Browse files

Simplified responses

  • Loading branch information...
1 parent 32cc4b7 commit b7d3dd51248e9811ec92531cb29f6bc17ba1f32e @tarcieri tarcieri committed Feb 21, 2012
Showing with 18 additions and 2 deletions.
  1. +9 −0 examples/hello_world.rb
  2. +8 −1 lib/reel/connection.rb
  3. +1 −1 spec/reel/server_spec.rb
View
@@ -0,0 +1,9 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'reel'
+
+Reel::Server.new('127.0.0.1', 1234) do |connection|
+ connection.respond :ok, "hello, world!"
+end
+
+sleep
View
@@ -22,7 +22,14 @@ def read_request
@request = Request.new(@parser.http_method, @parser.url, @parser.http_version, @parser.headers)
end
- def respond(response)
+ def respond(response, body = nil)
+ case response
+ when Symbol
+ response = Response.new(response, body)
+ when Response
+ else raise TypeError, "invalid response: #{response.inspect}"
+ end
+
response.render(@socket)
rescue Errno::ECONNRESET, Errno::EPIPE
# The client disconnected early
View
@@ -13,7 +13,7 @@
request.version.should eq "1.1"
request.url.should eq example_url
- connection.respond Reel::Response.new(:ok, response_body)
+ connection.respond :ok, response_body
handler_called = true
end

0 comments on commit b7d3dd5

Please sign in to comment.