Repository navigation
Offload local downloads to nginx via X-Accel-Redirect - #388
chapmanjacobd wants to merge 7 commits into
Conversation
Downloading a large video or audiobook still made Calibre-Web read the file in the Python process. Route local downloads through the same internal /protected-stream/ nginx location used for video playback, falling back to Flask only for staged copies outside the library root.
Without the matching nginx internal location the response would be empty, so default to Flask's streaming send_from_directory() and let video playback fall back to serve_book() when the option is off.
4dcdca2 to
289f708
Compare
Set CALIBRE_X_ACCEL_REDIRECT=1 so the updated Calibre-Web offloads local downloads (and video playback) to nginx's internal /protected-stream/ location instead of reading files into the Python process. Companion to iiab/calibre-web#388, closes iiab/calibre-web#79.
|
Why bother with the environment variable to control behavior? Isn't the sole purpose of the fork is to support iiab? From the splash page |
|
It's because then testing requires nginx. maybe we could make it the default though and add another flag for the current de-coupled behavior |
nginx now serves library downloads and video playback through its internal /protected-stream/ location by default, so large files no longer have to be read into Calibre-Web's memory. Restore the matching location in the bundled nginx config. Set CALIBRE_DISABLE_X_ACCEL_REDIRECT=1 to use Flask's streaming fallback when running without nginx or in tests. With this default, iiab/iiab#4579 no longer needs to set the old opt-in variable.
|
Side note: integration-test-chrome integration-test-firefox |
|
Seems the failure from the dup'd stanza introduced in e32d976 as from the failure at https://github.com/iiab/iiab/blob/master/roles/calibre-web/tasks/enable-or-disable.yml#L53-L60 might be related as that is 3 year old code prior to 'protected-stream'. |
|
Final nit would be 'runs-on', I think explicit is better than latest IMHO. |
|
ubuntu-latest is the most common convention for GHA workflows probably because if something is breaking due to it being the latest LTS then it's good to be aware of that.... I don't care that much one way or the other... However, I didn't introduce those lines nor touch them in this PR so it should probably be something discussed that becomes an org-wide change--and what is used in |
Playback of large videos was already moved to nginx in #315, but downloads still went through Flask. Downloading a large video or audiobook therefore still made Calibre-Web read the file in the Python process, which could OOM small-RAM machines.
This routes local downloads through the same internal
/protected-stream/nginx location, so nginx sends the file and Calibre-Web only returns a smallX-Accel-Redirectresponse.Content-TypeandContent-Dispositionare passed along so browsers still get the correct filename and attachment behavior.Because an
X-Accel-Redirectresponse has no body unless nginx has the matching internal location, the behavior is opt-in viaCALIBRE_X_ACCEL_REDIRECT=1. When it is not set, downloads keep using Flask's streamingsend_from_directory()and video playback falls back toserve_book(). This avoids breaking standalone and non-nginx installs.For IIAB this means adding the environment variable to the
calibre-web.serviceunit:IIAB's nginx template already provides the required internal location:
Flask still serves files outside the library root, such as staged kepubify or calibre-export copies in the temp directory, which nginx's alias cannot reach. The shared path-building logic handles
&and other characters that need percent-encoding.Closes #79