mirror of
https://github.com/iv-org/invidious.git
synced 2026-07-07 06:06:48 -05:00
fix(before_all): avoid double-write on halted responses to prevent HTTP/2 corruption
Store response body in env instead of writing directly; let halt() do the single write+close in the before_all block, eliminating Closed stream errors and ERR_HTTP2_PROTOCOL_ERROR on subsequent requests (e.g. /login).
This commit is contained in:
parent
623f715a8c
commit
5ad8fcfc4d
@ -202,9 +202,9 @@ before_all do |env|
|
||||
Invidious::Routes::BeforeAll.handle(env)
|
||||
|
||||
# If before_all flagged a halt (e.g. disabled page), stop the route handler.
|
||||
# Use halt with the already-set status code to prevent the route handler from running.
|
||||
if env.get?("halted")
|
||||
halt env, status_code: env.response.status_code
|
||||
if halted_status = env.get?("halted_status")
|
||||
body = env.get?("halted_body").try(&.as(String)) || ""
|
||||
halt env, status_code: halted_status.as(Int32), response: body
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -164,12 +164,9 @@ module Invidious::Routes::BeforeAll
|
||||
end
|
||||
|
||||
if page_key && !CONFIG.page_enabled?(page_key)
|
||||
env.response.status_code = 403
|
||||
env.set "halted", true
|
||||
|
||||
if path.starts_with?("/api/")
|
||||
env.response.content_type = "application/json"
|
||||
env.response.print({error: "Administrator has disabled this endpoint."}.to_json)
|
||||
env.set "halted_body", {error: "Administrator has disabled this endpoint."}.to_json
|
||||
else
|
||||
preferences = env.get("preferences").as(Preferences)
|
||||
locale = preferences.locale
|
||||
@ -178,7 +175,7 @@ module Invidious::Routes::BeforeAll
|
||||
error_message = I18n.translate(locale, "#{page_key}_page_disabled")
|
||||
|
||||
env.response.content_type = "text/html"
|
||||
env.response.print <<-HTML
|
||||
env.set "halted_body", <<-HTML
|
||||
<!DOCTYPE html>
|
||||
<html lang="#{locale}">
|
||||
<head>
|
||||
@ -209,6 +206,7 @@ module Invidious::Routes::BeforeAll
|
||||
HTML
|
||||
end
|
||||
|
||||
env.set "halted_status", 403
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user