storage manager: use canonical URL for image URLs.

Generate image URLs relative to the site's canonical URL instead of
relative to the domain of the current request.

This means that all subdomains of Danbooru - safebooru.donmai.us,
shima.donmai.us, saitou.donmai.us, and kagamihara.donmai.us - will use
image URLs from https://danbooru.donmai.us, instead of from the current
domain.

The main reason we did this before was so that we could generate either
http:// or https:// image URLs, depending on whether the current request
was HTTP or HTTPS, back when we tried to support both at the same time.
Now we support only HTTPS in production, so there's no need for this. It
was also pretty hacky, since it required storing the URL of the current
request in a per-request global variable in `CurrentUser`.

This also improves caching slightly, since users of safebooru.donmai.us
will receive cached images from danbooru.donmai.us.

Downstream boorus should make sure that the `canonical_url` and
`storage_manager` config options are set correctly. If you don't support
https:// in development, you should make sure to set the canonical_url
option to http:// instead of https://.
This commit is contained in:
evazion
2021-03-15 01:58:21 -05:00
parent f93b1fe478
commit 0f90ae0fed
4 changed files with 10 additions and 18 deletions

View File

@@ -140,7 +140,6 @@ class ApplicationController < ActionController::Base
CurrentUser.user = nil
CurrentUser.ip_addr = nil
CurrentUser.safe_mode = false
CurrentUser.root_url = root_url.chomp("/")
end
# Skip setting the session cookie if the response is being publicly cached to