From ace195c9d42a8d23a29a0ba93015183dbf5ac2d3 Mon Sep 17 00:00:00 2001 From: Philip Wiebe Date: Thu, 30 Jan 2014 13:23:01 -0500 Subject: [PATCH] added 408 status on timeout. --- .gitignore | 1 + lib/puma/client.rb | 7 +++++++ lib/puma/const.rb | 3 +++ lib/puma/reactor.rb | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eebfbb28..c8fc6114 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ pkg tmp .rbx/ Gemfile.lock +.idea/ diff --git a/lib/puma/client.rb b/lib/puma/client.rb index 313d5b17..4252f6b7 100644 --- a/lib/puma/client.rb +++ b/lib/puma/client.rb @@ -267,6 +267,13 @@ module Puma end end + def write_408 + begin + @io << ERROR_408_RESPONSE + rescue StandardError + end + end + def write_500 begin @io << ERROR_500_RESPONSE diff --git a/lib/puma/const.rb b/lib/puma/const.rb index 47aca798..3763f3d2 100644 --- a/lib/puma/const.rb +++ b/lib/puma/const.rb @@ -59,6 +59,9 @@ module Puma # The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff. ERROR_404_RESPONSE = "HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\nNOT FOUND".freeze + # The standard empty 408 response for requests that timed out. + ERROR_408_RESPONSE = "HTTP/1.1 408 Request Timeout\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\n".freeze + CONTENT_LENGTH = "CONTENT_LENGTH".freeze # Indicate that there was an internal error, obviously. diff --git a/lib/puma/reactor.rb b/lib/puma/reactor.rb index 5707e1f2..73ba5736 100644 --- a/lib/puma/reactor.rb +++ b/lib/puma/reactor.rb @@ -98,8 +98,9 @@ module Puma while @timeouts.first.timeout_at < now c = @timeouts.shift - sockets.delete c + c.write_408 c.close + sockets.delete c break if @timeouts.empty? end