docs.rs
docs.rs copied to clipboard
Image camo
When an image is included in a README or a doc file, docs.rs links directly to it. It should do like GitHub does and do proxying and caching for it.
It might make sense to do a "quick" grep across all image tags currently rendered to look for some common domains. If the image is on imgur.com, it's already on a CDN. If it's a github link, it might be possible to rewrite the link to https://rawgit.com instead.
This feels a little out of scope. From my understanding, the request is that given a link to an image hosted on an arbitrary domain, docs.rs should download a copy of that image and host it itself so that it doesn't break/is served from the same CDN as the rest of the content.
- I'm not sure what benefit this has. Most of big image hosting services will have much better CDNs than we do.
- It expands the scope of docs.rs enormously. Currently we host
- pages rendered by rustdoc
- pages generated by build.rs
- nothing else
After this change we'd also store
- every image any generated page links to
which means that you could potentially overload the server just by publishing a list of the million most popular images.
With that in mind, I don't think this is worth implementing.
I think this is something that we should eventually do, as it improves the privacy of users visiting docs.rs. But it's pretty low priority.
We don’t need to store images long-term. If we are just proxying and can integrate well with a CDN to do the caching for us then this seems feasible.
From what I see this would involve rewriting the image-tags in the HTML, or hooking into rustdoc in how it generates the tags.
Both would be (I think) subject to a edge case where custom JS could still generate image links that point somewhere else, which we could solve with using img-src CSP.
The proxy itself could probably be a simple proxy endpoint. Caching it would be tricky, since I assume these external images are often dynamically generated, and used to inject dynamic content into the static docs.
The privacy improvement is IMO a valid reason to work on this.