mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Cache failed onebox URL request server-side (#8421)
We already cache failed onebox URL requests client-side, we now want to cache this on the server-side for extra protection. failed onebox previews will be cached for 1 hour, and any more requests for that URL will fail with a 404 status. Forcing a rebake via the Rebake HTML action will delete the failed URL cache (like how the oneboxer preview cache is deleted).
This commit is contained in:
@@ -19,6 +19,8 @@ class OneboxController < ApplicationController
|
||||
invalidate = params[:refresh] == 'true'
|
||||
url = params[:url]
|
||||
|
||||
return render(body: nil, status: 404) if Oneboxer.recently_failed?(url)
|
||||
|
||||
hijack do
|
||||
Oneboxer.preview_onebox!(user_id)
|
||||
|
||||
@@ -34,6 +36,7 @@ class OneboxController < ApplicationController
|
||||
Oneboxer.onebox_previewed!(user_id)
|
||||
|
||||
if preview.blank?
|
||||
Oneboxer.cache_failed!(url)
|
||||
render body: nil, status: 404
|
||||
else
|
||||
render plain: preview
|
||||
|
||||
Reference in New Issue
Block a user