diff --git a/lib/async/http/protocol/http1/server.rb b/lib/async/http/protocol/http1/server.rb index 71fc9de0..f5d9a168 100644 --- a/lib/async/http/protocol/http1/server.rb +++ b/lib/async/http/protocol/http1/server.rb @@ -3,6 +3,7 @@ # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. # Copyright, 2020, by Igor Sidorov. +# Copyright, 2023, by Thomas Morgan. require_relative 'connection' @@ -14,6 +15,9 @@ 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 diff --git a/spec/async/http/protocol/http11_spec.rb b/spec/async/http/protocol/http11_spec.rb index 697e8f86..d16bf8ba 100755 --- a/spec/async/http/protocol/http11_spec.rb +++ b/spec/async/http/protocol/http11_spec.rb @@ -3,6 +3,7 @@ # Released under the MIT License. # Copyright, 2017-2023, by Samuel Williams. # Copyright, 2018, by Janko Marohnić. +# Copyright, 2023, by Thomas Morgan. require 'async/http/protocol/http11' require_relative 'shared_examples' @@ -10,6 +11,25 @@ RSpec.describe Async::HTTP::Protocol::HTTP11 do it_behaves_like Async::HTTP::Protocol + context 'bad requests' do + include_context Async::HTTP::Server + + around do |example| + current = Console.logger.level + Console.logger.fatal! + + example.run + ensure + Console.logger.level = current + end + + it "should fail cleanly when path is empty" do + response = client.get("") + + expect(response.status).to be == 400 + end + end + context 'head request' do include_context Async::HTTP::Server