Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify request flow to allow content-type checks #440

Open
jimlambie opened this issue Oct 10, 2018 · 0 comments
Open

Modify request flow to allow content-type checks #440

jimlambie opened this issue Oct 10, 2018 · 0 comments

Comments

@jimlambie
Copy link
Contributor

The request flow in CDN is currently:

  • user requests a URL, for example http://cdn.somedomain.tech/path/to/file.jpg
  • CDN determines the asset type based on the URL, possibly using a file extension
  • CDN invokes an AssetHandler (for example handlers/image.js). If the URL has no file extension, handlers/default.js is used.
  • the AssetHandler instantiates a StorageHandler, based on the CDN configuration. For example, if the AssetHandler is an ImageHandler, CDN obtains the storage type from the "images" section of the configuration file.
  • the AssetHandler calls the StorageHandler's get() method to attempt to retrieve the file

This flow is awkward and cumbersome, and we have to make a lot of assumptions about files that we really shouldn't be making. For example in the past we assumed if no extension was in the URL then the ImageHandler should be forced to respond to the request as if it was a JPG. That "feature" was removed so that we can handle URLs that are requesting HTML pages from a configured remote endpoint, allowing passthrough HTML caching for requests such as https://dadi.cloud/en/team <-- no extension and certainly not forceable into a JPG.

The correct way to handle the above may be to invoke the StorageHandler first,
retrieve the file, determine the content-type of the response and only then determine which AssetHandler should be used. One benefit of this approach is that we can fail fast if the file cannot be found.

However there may be a case where this approach doesn't work. Another discussion in progress is how we actually configure CDN's locations of assets and images. It'd be great to allow configuration of locations on a mime type basis, in which case for known mime types (i.e. URLs containing an extension) we'd be able to instantiate a StorageHandler using the appropriate configuration for that mime type. How we handle this for extension-less URLs still remains a question...

Issues possibly involved: #349, #351, #437

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant