diff --git a/src/webserver/WebServer.jl b/src/webserver/WebServer.jl index d8a5fef6d7..9c53d04ad6 100644 --- a/src/webserver/WebServer.jl +++ b/src/webserver/WebServer.jl @@ -190,9 +190,17 @@ function run!(session::ServerSession) s = session.options.security s.require_secret_for_access || s.require_secret_for_open_links end + finish() = try + HTTP.setstatus(http, 403) + HTTP.startwrite(http) + HTTP.closewrite(http) + catch e + if !(e isa Base.IOError) + rethrow(e) + end + end if !secret_required || is_authenticated(session, http.message) try - HTTP.WebSockets.upgrade(http) do clientstream if HTTP.WebSockets.isclosed(clientstream) return @@ -246,17 +254,13 @@ function run!(session::ServerSession) bt = stacktrace(catch_backtrace()) @warn "HTTP upgrade failed for unknown reason" exception = (ex, bt) end - end - else - try - HTTP.setstatus(http, 403) - HTTP.startwrite(http) - HTTP.closewrite(http) - catch e - if !(e isa Base.IOError) - rethrow(e) + finally + if isopen(http) && !iswritable(http) + finish() end end + else + finish() end else # then it's a regular HTTP request, not a WS upgrade