Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

return Content-Disposition header alongside content #527

Closed
acud opened this issue May 9, 2018 · 7 comments
Closed

return Content-Disposition header alongside content #527

acud opened this issue May 9, 2018 · 7 comments

Comments

@acud
Copy link
Member

acud commented May 9, 2018

The HTTP server should return a Content-Disposition Header alongside with content so that browsers/http clients could know how to save a file.

The server should determine the filename according to what's in the path section of the URI/Manifest path entry, or fall back to the content hash at worst case.

e.g. Content-Disposition: attachment; filename="filename.jpg"

@nizsheanez
Copy link

I would like to take this ticket.

A bit investigated:

  • Chrome doesn't respect Content-Disposition header if Content-Type header is absent (FireFox does)
  • default swarm up /path/to/example.md calling swarm/api.UploadTar which save empty ContentType. There are hdr.Xattrs and hdr.PAXRecords have empty content type value.

Will discover more tomorrow.

@acud
Copy link
Member Author

acud commented Sep 20, 2018

@nizsheanez you can have it :) please join our gitter channel for any questions that might arise.

@nizsheanez
Copy link

Thank you.

Here is the reason:

  • I did upload .md file
  • cmd/swarm.detectMimeType did try detect ContentType by the file extension, but had no success because .md extension is not in mime.builtinTypesLower map. And cmd/swarm.detectMimeType returned empty string

But:

Good news - cmd/swarm.detectMimeType using http.DetectContentType which already follow fallback to "application/octet-stream".
I will change cmd/swarm.detectMimeType behavior: if detection by file extension return empty string - it will try content-based detection by http.DetectContentType

Do i need change swarm/api.Get to return "application/octet-stream" if mimeType is empty?

@acud
Copy link
Member Author

acud commented Sep 21, 2018

@nizsheanez correct; I opened a related issue yesterday (for different reasons) about the topic - that we should switch to magic-number based MIME type detection and dump the extension based detection. it is also not being used properly for when uploading a directory. see #944

both should use magic number detection.

I think that for one thing - the uploading code should be fixed to fall back to octet-stream, then surely there has to be a fallback on the api/http package (not sure if api should care about MIME types). We can start with this and observe the results.

nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 21, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 21, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 21, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 21, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 21, 2018
@nizsheanez
Copy link

nizsheanez commented Sep 21, 2018

Created PR about Content-Disposition first:
#945

Also, looks like need to review all places where expected "Content-Type" of file from client and:

btw, is that ok that i keeping discussion here instead of Gitter? In my head - Gitter for some common questions.

nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 22, 2018
…sphere#527, ethersphere#944)

Changed swarm/api.Upload:
 - when using WaitGroup no reason to use done counter.
 - f.Close() must be called in Defer - otherwise panic or future added early return will cause leak of file descriptors
 - use common DetectContentType method
 - one error was suppressed
@acud
Copy link
Member Author

acud commented Sep 22, 2018

Sure let's keep the conversation here.

Adding the validation is a good idea - go for it. Same for fallbacks.

You should be able to cover everything from the http package and the upload.go file - these are the relevant entry points for mime.

The rest of the codebase only cares about mime types in the context of manifest traversals - which in this case looks for an application/bzz-manifest+json content type in order to continue traversing a manifest trie, and this is the only case you should watch out for (although I just checked that mime.ParseMediaType("application/bzz-manifest+json") passes and does not throw an error - so we should be good with this).

nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 22, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 22, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 22, 2018
@nizsheanez
Copy link

Done

nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 22, 2018
…eReview (ethersphere#527, ethersphere#944)

Fixes for ethersphere#945

- revert back channel which handle I/O throttling
- add tests on real files
- add tests when file extension doesn't match content
- move code to existing files, no real reason to have dedicated file for such functions
- move http headers validation to swarm/api/http package
- swarm.Open now checking content of file to detect Content Type
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 23, 2018
…phere#944)

- add hardcoded mime types list
- follow stdlib way of ContentType checking
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 23, 2018
…where possible (ethersphere#527, ethersphere#944)

- simplified I/O throttling by semaphore primitive
- don't use URL from request, use parsed Swarm uri for file name detection
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 23, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
…on only since go1.11, a bit of copy-paste (ethersphere#527, ethersphere#944)

- added text/markdown content type
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
…on only since go1.11, a bit of copy-paste (ethersphere#527, ethersphere#944)

- added text/markdown content type
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
…ion from attachment to inline (ethersphere#527, ethersphere#944)

- If I go to bzz://mysite.eth/index.html in my browser, I expect to see the HTML in the browser, not download it to a local file.
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 24, 2018
…ion from attachment to inline (ethersphere#527, ethersphere#944)

- If I go to bzz://mysite.eth/index.html in my browser, I expect to see the HTML in the browser, not download it to a local file.
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 26, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 26, 2018
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 28, 2018
…http: cross-platform Content-Type detection, add Content-Disposition http header (ethersphere#527, ethersphere#944)

- Mime types generator (Standard "mime" package rely on system-settings, see mime.osInitMime)
- Changed swarm/api.Upload:
    - simplify I/O throttling by semaphore primitive and use file name where possible
    - f.Close() must be called in Defer - otherwise panic or future added early return will cause leak of file descriptors
    - one error was suppressed
nizsheanez added a commit to nizsheanez/go-ethereum that referenced this issue Sep 28, 2018
…http: cross-platform Content-Type detection, add Content-Disposition http header (ethersphere#527, ethersphere#944)

- Mime types generator (Standard "mime" package rely on system-settings, see mime.osInitMime)
- Changed swarm/api.Upload:
    - simplify I/O throttling by semaphore primitive and use file name where possible
    - f.Close() must be called in Defer - otherwise panic or future added early return will cause leak of file descriptors
    - one error was suppressed
@acud acud closed this as completed Oct 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants