-
Notifications
You must be signed in to change notification settings - Fork 29
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
Content Type set by HTTP Gateway #152
Comments
wouldn't his mean that every request to the gateway becomes two request (one to the actual content, the other to figure out if .htaccess-clone exists). This may be expensive. And. if using different extensions on the filename is effectively setting the content type guessed for that file, isn't this precisely a way to hint/override the content type of certain content? |
It looks that way, however (iiuc) if gateway wants to resolve This means checking if
Unfortunately extension-based sniffing relies on arbitrary mapping hardcoded in go-ipfs and works only for popular file types, such as SVG. Publishing file with Real life example:
|
Just FYI there is accepted proposal ipfs/kubo#6214 for support of |
Has much progressed in terms of having a 404 page for ipfs hosted websites? |
I believe |
An alternative idea is to do what we did for opt-in |
What if I want to serve media from an IPFS gateway for my website, but I do not want to allow |
Good news, the default IPFS gateway returns EDIT: Same isn't true for |
HTTP Gateway does content-type sniffing based on golang.org/src/net/http/sniff.go and file extension. js-ipfs uses similar setup.
Problem: there is no mechanism for website creator to override returned content-type, setting custom file extension works only for some file types.
Example
The same data produces different content-type, depending on request path.
SVG image
https://ipfs.io/ipfs/QmVdFJJBiQkVKFcvXu4WzySbZ7KnCW6uGWLJqZz5FnRWjk/ipfs-logo.svg
→ returned as
image/svg+xml
XML document
https://ipfs.io/ipfs/QmVdFJJBiQkVKFcvXu4WzySbZ7KnCW6uGWLJqZz5FnRWjk/ipfs-logo.xml
→ returned as
text/xml
Unknown extension
https://ipfs.io/ipfs/QmVdFJJBiQkVKFcvXu4WzySbZ7KnCW6uGWLJqZz5FnRWjk/ipfs-logo.foo
→ returned as
text/plain
Raw CID
https://ipfs.io/ipfs/QmTqZhR6f7jzdhLgPArDPnsbZpvvgxzCZycXK7ywkLxSyU
→ returned as
text/plain
Raw CID + explicit filename
https://ipfs.io/ipfs/QmTqZhR6f7jzdhLgPArDPnsbZpvvgxzCZycXK7ywkLxSyU?filename=/ipfs-logo.svg
→ returned as
image/svg+xml
Motivation
We want IPFS to become viable solution for hosting websites.
At the HTTP level, as a bare minimum, website owners expect to able to override:
Ideas to explore
(A) Embedding content-type in DAG-PB (UnixFS metadata)
One way to address this is to support embedding Content-Type in UnixFS DAG metadata.
It would be opt-in (like
mode
andmtime
).TBD if
filename
should override content type embedded in the dag.This is tracked in ipfs/specs#364
(B) Drop-in config to override content-type per directory
@warpfork noted that DAG metadata may not be the best place for storing content-type:
My take on this is:
mtime
andmode
– UnixFS 1.5 embedds them in dag-pb_headers
to the directory, and Gateway would do the right thing when resource from directory or its subdirectories are requestedX-Content-Type-Options: nosniff
)See
_headers
in ipfs/specs#257References
cc @olizilla @autonome
The text was updated successfully, but these errors were encountered: