Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Gateway content-type response header #224

Closed
uptownhr opened this issue Feb 7, 2017 · 6 comments
Closed

Gateway content-type response header #224

uptownhr opened this issue Feb 7, 2017 · 6 comments

Comments

@uptownhr
Copy link

uptownhr commented Feb 7, 2017

Is there a way to set the header of what the gateway will return as content-type. I have an issue right now when serving svg files. Since the content-type is text, browsers do not recognize it properly and will not display the image.

@lidel
Copy link

lidel commented Feb 7, 2017

I feel this requires clarification, as it may not be clear what is wrong on the first sight.

Sample SVG image at /ipfs/QmWBNMp6JxXj5aYrpef8z2xaPC7DeGftG4jTy6EyF958o4
is returned with Content-Type: text/xml and when opened directly it renders just fine under both Firefox 51 and Chromium 56. 👌

The problem is that resource returned as text/xml can't be rendered as <img src=" or CSS background. If you open svg-mimetype-example.html you will see <img> is not rendered and alt text is displayed instead. 👎

My guess is that go-ipfs probably uses standard mime-type sniffer from golang [1] which defaults to text/xml
Correct mime-type for image contexts in browser is image/svg+xml [2,3]

It does not seem to work correctly now, but you may want to subscribe to related issues about mime-type in go-ipfs:


1: https://golang.org/src/net/http/sniff.go
2: https://www.w3.org/TR/SVGTiny12/mimereg.html
3: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Getting_Started#SVG_File_Types

@uptownhr
Copy link
Author

uptownhr commented Feb 8, 2017

awesome, thank you

@ghost
Copy link

ghost commented Feb 8, 2017

Maybe it helps to wrap the svg in a directory, in order to have it addressed with a .svg filename:

> ipfs add -w file.svg
added Qmsvg file.svg
added Qmfoo
# => /ipfs/Qmfoo/file.svg

@lidel
Copy link

lidel commented Feb 8, 2017

Indeed! If extension is .svg:

<img src="https://ipfs.io/ipfs/QmQ48wa7jc9JZJ9Lc1XCkuwa3FUYeXcMPJi3vAD78VbBM1/sample.svg" alt="if you see this text it means SVG image failed to load"/>

it IS returned as Content-Type:"image/svg+xml" and renders correctly:
/ipfs/QmRYdrzpspUpeDgn1au2L6jNYuo9SZN2TD4FABn9dY9jra/svg-mimetype-example2.html

@Kubuxu
Copy link

Kubuxu commented Feb 8, 2017

The content type detection from the content is only heuristic, so it is better to use file extension for deterministic content type.

@madavieb
Copy link

This issue has been moved to https://discuss.ipfs.io/t/gateway-content-type-response-header/357.

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

No branches or pull requests

4 participants