Skip to content

Commit f64fa68

Browse files
committed
make fail_request properly finish the response
1 parent e265f3f commit f64fa68

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/async/http/protocol/http1/server.rb

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2018-2023, by Samuel Williams.
55
# Copyright, 2020, by Igor Sidorov.
6+
# Copyright, 2023, by Thomas Morgan.
67

78
require_relative 'connection'
89

@@ -14,6 +15,9 @@ class Server < Connection
1415
def fail_request(status)
1516
@persistent = false
1617
write_response(@version, status, {}, nil)
18+
write_body(@version, nil)
19+
rescue Errno::ECONNRESET, Errno::EPIPE
20+
# Handle when connection is already closed
1721
end
1822

1923
def next_request

spec/async/http/protocol/http11_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
# Released under the MIT License.
44
# Copyright, 2017-2023, by Samuel Williams.
55
# Copyright, 2018, by Janko Marohnić.
6+
# Copyright, 2023, by Thomas Morgan.
67

78
require 'async/http/protocol/http11'
89
require_relative 'shared_examples'
910

1011
RSpec.describe Async::HTTP::Protocol::HTTP11 do
1112
it_behaves_like Async::HTTP::Protocol
1213

14+
context 'bad requests' do
15+
include_context Async::HTTP::Server
16+
17+
it "should fail cleanly when path is empty" do
18+
response = client.get("")
19+
20+
expect(response.status).to be == 400
21+
end
22+
end
23+
1324
context 'head request' do
1425
include_context Async::HTTP::Server
1526

0 commit comments

Comments
 (0)