Onebox fail with 429 error should still create valid <img> tags

On my Discourse forum users are encouraged to use external image hosting services when possible. The most common is Imgur, which after a while starts rate-limiting the Discourse server with a 429 error. While this is an unsolvable problem with Imgur, Discourse also doesn’t handle it optimally. Currently when Imgur throws a 429 error Discourse interprets it as if it were an invalid image link and it just displays the image URL with <a> tags. But there is nothing preventing individual users from viewing those images inline in Discourse since their browser and IP are different. Discourse should still generate valid HTML to display the image. For example:

https://i.imgur.com/eHltaVt.jpeg
This URL gets rate-limited on my server and Discourse just generates a link:
<a href="https://i.imgur.com/eHltaVt.jpeg" target="_blank" rel="noopener noreferrer" tabindex="-1">https://i.imgur.com/eHltaVt.jpeg</a>

But the following HTML works fine to display the image within the end-user’s browser, both in the post preview and in the baked post:
<img src="https://i.imgur.com/eHltaVt.jpeg">
That is the HTML that Discourse should generate even if it receives a 429 when the server hits the URL, and it should only leave the naked URL if it gets a 404 error.

3 Likes