Skip to content

Commit

Permalink
Disable response buffering for /admin/logs (#197)
Browse files Browse the repository at this point in the history
This patch disables buffering for the streaming endpoint /admin/logs by
setting the special nginx proxy response header X-Accel-Buffering to
"no". Even though the default buffering settings seems to work fairly
well without too many buffer hiccups it is recommended to disable
buffering for this type of streaming endpoints.

As an alternative, buffering can be disabled in the nginx config by
introducing a new /admin/logs location block, but since the scope here
is very narrow it seems much simpler to just set the header.
  • Loading branch information
fredrikekre authored Dec 5, 2023
1 parent 39d7695 commit 38adc89
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/admin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ function handle_admin_authenticated(http::HTTP.Stream)
color = get(params, "color", "true") == "true"
req_level = get(params, "level", "info") == "debug" ? Logging.Debug : Logging.Info
HTTP.setheader(http, "Content-Type" => "text/plain")
# Tell nginx to not buffer the response, see
# https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering
HTTP.setheader(http, "X-Accel-Buffering" => "no")
HTTP.startwrite(http)
attach(ADMIN_LOGGER) do level, message
level < req_level && return
Expand Down

0 comments on commit 38adc89

Please sign in to comment.