lib/async/http/protocol/http1/server.rb in async-http-0.60.2 vs lib/async/http/protocol/http1/server.rb in async-http-0.61.0
- old
+ new
@@ -1,10 +1,11 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2018-2023, by Samuel Williams.
# Copyright, 2020, by Igor Sidorov.
+# Copyright, 2023, by Thomas Morgan.
require_relative 'connection'
module Async
module HTTP
@@ -12,10 +13,13 @@
module HTTP1
class Server < Connection
def fail_request(status)
@persistent = false
write_response(@version, status, {}, nil)
+ write_body(@version, nil)
+ rescue Errno::ECONNRESET, Errno::EPIPE
+ # Handle when connection is already closed
end
def next_request
# The default is true.
return unless @persistent
@@ -77,11 +81,11 @@
else
head = request.head?
version = request.version
# Same as above:
- request = nil unless body
+ request = nil unless request.body
response = nil
write_body(version, body, head, trailer)
end
@@ -92,20 +96,21 @@
write_response(@version, 500, {})
write_body(request.version, nil)
end
# Gracefully finish reading the request body if it was not already done so.
- request&.finish
+ request&.each{}
# This ensures we yield at least once every iteration of the loop and allow other fibers to execute.
task.yield
rescue => error
raise
ensure
body&.close(error)
end
end
end
+
end
end
end
end
end