Closed Melonking906 closed 8 months ago
The fallback is nothing more than a redirect, which will trigger on any errors. In your example reddit seems to be actively blocking the request from the proxy, so it will fail with error 403, or redirect when &default=
is provided.
The standard behaviour of the proxy is to just show the error, instead of returning an unexpected redirect to the original image. Showing the error is best practice, because something went wrong, which should be investigated.
We could maybe implement a redirect when you'd just provide &default
without any arguments, and then redirect to the &url=
. That could indeed shorten the total URL, which sounds logical.
Or did you want a configurable variable in the code to tune this behaviour? Maybe I misunderstood your request.
Nope you understood perfectly! Your suggestion would be ideal. In my case because Im running a forum, the images being proxied are user input, getting them to display is the priority and errors are not really an issue, as long as most images are working ok.
@kleisauke: Shall we put this on the to-do list?
This has been implemented with commit adc6b9ab6d0be1c0c65b37757577ba5b6db6f122, which has just been rolled out to production. Thanks for reporting this!
Documentation will be updated later to reflect this.
Documentation has been updated. https://wsrv.nl/docs/format.html#default-image
I have found that sometimes images fail to process in the cache but if I set their default as the original image, it acts as a fallback and the image successfully loads.
For example this might fail to load anything: Eg: https://myimagecache.site.com?url=image.somesite.net/duck.jpg&w=1000&we&n=-1
But this will successfully load the image for the end user: https://myimagecache.site.com?url=image.somesite.net/duck.jpg&w=1000&we&n=-1&default=https://image.somesite.net/duck.jpg
The issue is now I have a 2x long URL which is ugly and could be an issue if the source image URL was already very long.
It would be good if I could just flag the default to fall back to the source image if something goes wrong.
EDIT: Iv found a real world example of this happening - this URL will fail to load with a 404 error:
https://images.melonland.net/?url=https%3A%2F%2Fi.redd.it%2Fbest-dinosaur-themed-megazord-v0-bfs51aj5im591.jpg%3Fwidth%3D640%26format%3Dpjpg%26auto%3Dwebp%26s%3D34cf5a6d5bc4dac3e699f8f44c294113e7f4e850&w=1200&fit=inside&we&q=85&il&n=-1
However when you include a default value with the same source URL it works fine:
https://images.melonland.net/?url=https%3A%2F%2Fi.redd.it%2Fbest-dinosaur-themed-megazord-v0-bfs51aj5im591.jpg%3Fwidth%3D640%26format%3Dpjpg%26auto%3Dwebp%26s%3D34cf5a6d5bc4dac3e699f8f44c294113e7f4e850&w=1200&fit=inside&we&q=85&il&n=-1&default=https%3A%2F%2Fi.redd.it%2Fbest-dinosaur-themed-megazord-v0-bfs51aj5im591.jpg%3Fwidth%3D640%26format%3Dpjpg%26auto%3Dwebp%26s%3D34cf5a6d5bc4dac3e699f8f44c294113e7f4e850