jasonraimondi / url-to-png

Selfhosted. URL to PNG utility featuring parallel rendering using Playwright for screenshots and with storage caching via Local, S3, or CouchDB
https://jasonraimondi.github.io/url-to-png/
MIT License
156 stars 28 forks source link

Forward HTTP resposne codes #5

Closed nagylzs closed 2 years ago

nagylzs commented 3 years ago

When the given URL returns HTTP 404, then the service returns the rendered image with HTTP 200. This is bad, because the caller cannot tell if there was an error or not. Of course, it is possible (in most cases) to do the original GET request and check for HTTP error codes before asking for a rendered PNG. But that is not very efficient.

Could you please change the program to return the original HTTP code for the request? I understand that it may break compatibility with current users, so here is my proposal with full backward compatibility.

  1. Add a new response header called "Original-Http-Response-Code" and send the original response there. This won't break compatibility at all.
  2. Add a new parameter "abort_on_error=true". When this parameter is set, then return the request with the original HTTP error code, without rendering and sending the PNG file. So if a user only needs PNG images for URLs that have no errors, then this can speed up things. (By "no error" I meant 200,301,302,304 etc. Anything above 400 is an error)
jasonraimondi commented 3 years ago

I attempted to catch and return status codes as explained here, but it seems like it was not working as expected.

Please feel free to take a look at this branch: https://github.com/jasonraimondi/url-to-png/tree/status-codes and see if you are able to get it working as expected.