Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connection without response on status code 444 #1134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/Servers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,22 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)
# invokelatest becuase the perf is negligible, but this makes live-editing handlers more Revise friendly
@debugv 1 "invoking handler"
Base.invokelatest(f, http)
# If `startwrite()` was never called, throw an error so we send a 500 and log this
if isopen(http) && !iswritable(http)
if request.response.status == 444
# If the response code is set to 444 simply close the
# connection similar to nginx
close(c)
elseif isopen(http) && !iswritable(http)
# If `startwrite()` was never called, throw an error so we send a 500 and log this
error("Server never wrote a response")
else
@debugv 1 "closeread"
closeread(http)
@debugv 1 "closewrite"
closewrite(http)
if c.state != CLOSING
c.state = IDLE
end
end
@debugv 1 "closeread"
closeread(http)
@debugv 1 "closewrite"
closewrite(http)
c.state = IDLE
catch e
# The remote can close the stream whenever it wants to, but there's nothing
# anyone can do about it on this side. No reason to log an error in that case.
Expand Down
13 changes: 13 additions & 0 deletions test/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ end # @testset
@test TEST_COUNT[] == 4
end # @testset

@testset "444" begin
server = HTTP.listen!() do http
HTTP.setstatus(http, 444)
end
port = server.listener.hostport
try
errr = try HTTP.get("http://localhost:$(port)", retry=false) catch e e end
@test errr isa HTTP.RequestError && errr.error isa EOFError
finally
close(server)
end
end

@testset "access logging" begin
local handler = (http) -> begin
if http.message.target == "/internal-error"
Expand Down
Loading