Skip to content

Commit

Permalink
Fix #2734
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Jun 3, 2024
1 parent 80c71ea commit 0d1306f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0d1306f

Please sign in to comment.