Skip to content

Commit

Permalink
Fix #2734 (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Jun 25, 2024
1 parent f135748 commit db0660b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,18 @@ 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)
write(http, "Forbidden")
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
Expand Down Expand Up @@ -246,17 +255,14 @@ 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 we never wrote a response, then do it now
if isopen(http) && !iswritable(http)
finish()
end
end
else
finish()
end
else
# then it's a regular HTTP request, not a WS upgrade
Expand Down

0 comments on commit db0660b

Please sign in to comment.