Permalink
Browse files

formatting

  • Loading branch information...
dj2 committed Jan 19, 2012
1 parent cf93bbb commit b9a4f02bdcd79590f6a71a87ab2df229fa1a0e04
Showing with 12 additions and 9 deletions.
  1. +6 −3 examples/early_abort.rb
  2. +6 −6 lib/goliath/request.rb
View
@@ -4,6 +4,7 @@
class EarlyAbort < Goliath::API
include Goliath::Validation
+
MAX_SIZE = 10
TEST_FILE = "/tmp/goliath-test-error.log"
@@ -12,7 +13,8 @@ def on_headers(env, headers)
env['async-headers'] = headers
if env['HTTP_X_CRASH'] && env['HTTP_X_CRASH'] == 'true'
- raise Goliath::Validation::NotImplementedError.new("Can't handle requests with X-Crash: true.")
+ raise Goliath::Validation::NotImplementedError.new(
+ "Can't handle requests with X-Crash: true.")
end
end
@@ -22,7 +24,8 @@ def on_body(env, data)
size = env['async-body'].size
if size >= MAX_SIZE
- raise Goliath::Validation::BadRequestError.new("Payload size can't exceed #{MAX_SIZE} bytes. Received #{size.inspect} bytes.")
+ raise Goliath::Validation::BadRequestError.new(
+ "Payload size can't exceed #{MAX_SIZE} bytes. Received #{size.inspect} bytes.")
end
end
@@ -31,7 +34,7 @@ def on_close(env)
end
def response(env)
- File.open(TEST_FILE, "w+") { |f| f << "response that should not be here"}
+ File.open(TEST_FILE, "w+") { |f| f << "response that should not be here\n"}
[200, {}, "OK"]
end
end
View
@@ -20,7 +20,7 @@ class Request
# Allow user to redefine how fibers are handled, the
# default is to spawn a new fiber each time but another
# option is to use a pool of fibers.
- #
+ #
class << self
attr_accessor :execute_block
end
@@ -29,7 +29,6 @@ class << self
Fiber.new(&block).resume
end
-
def initialize(app, conn, env)
@app = app
@conn = conn
@@ -185,11 +184,12 @@ def post_process(results)
begin
@response.status, @response.headers, @response.body = status, headers, body
@response.each { |chunk| @conn.send_data(chunk) }
+
@env[RACK_LOGGER].info("Status: #{@response.status}, " +
- "Content-Length: #{@response.headers['Content-Length']}, " +
- "Response Time: #{"%.2f" % ((Time.now.to_f - @env[:start_time]) * 1000)}ms")
+ "Content-Length: #{@response.headers['Content-Length']}, " +
+ "Response Time: #{"%.2f" % ((Time.now.to_f - @env[:start_time]) * 1000)}ms")
- @conn.terminate_request(keep_alive)
+ @conn.terminate_request(keep_alive)
rescue Exception => e
server_exception(e)
end
@@ -208,7 +208,7 @@ def post_process(results)
# @return [Nil]
def server_exception(e)
if e.is_a?(Goliath::Validation::Error)
- status, headers, body = [e.status_code, {}, ('{"error":"%s"}'%e.message)] #
+ status, headers, body = [e.status_code, {}, ('{"error":"%s"}' % e.message)]
else
@env[RACK_LOGGER].error("#{e.message}\n#{e.backtrace.join("\n")}")
status, headers, body = [500, {}, e.message || 'An error happened']

0 comments on commit b9a4f02

Please sign in to comment.