crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.47k stars 1.62k forks source link

HTTP::StaticFileHandler should support 206 Partial Content feature #8954

Closed 636f7374 closed 1 year ago

636f7374 commented 4 years ago

Summary

Specifications

Sample

GET /audio/... HTTP/1.1
Host: audio-akp-quic-control-spotify-com.akamaized.net
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Sec-Fetch-Dest: empty
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
DNT: 1
Accept: */*
Origin: https://open.spotify.com
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Referer: https://open.spotify.com/
Accept-Encoding: identity
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7
Range: bytes=495259-660589
HTTP/1.1 206 Partial Content
Last-Modified: Thu, 21 Nov 2019 19:49:02 GMT
ETag: "..."
Content-Type: application/octet-stream
Accept-Ranges: bytes
Cache-Control: no-transform, max-age=30745172
Cache-Control: max-age=315360000, no-transform
Date: Fri, 27 Mar 2020 18:53:39 GMT
Connection: keep-alive
Access-Control-Max-Age: 86400
Access-Control-Allow-Headers: range, pragma, cache-control
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: *
Expires: Mon, 25 Mar 2030 18:53:39 GMT
Content-Range: bytes 495259-660589/3592935
Content-Length: 165331
GET http://localhost:8080/traditional/small.dat HTTP/1.1
Host: localhost:8080
Connection: close
Accept: */*
Accept-Encoding: gzip
User-Agent: Jetty/9.4.19.v20190610
Range: bytes=2275-4550,6825-9100,11375-13650,15925-18200
HTTP/1.1 206 Partial Content
Date: Wed, 15 Nov 2015 06:25:24 GMT
Last-Modified: Wed, 15 Nov 2015 04:58:08 GMT
Content-Length: 1741
Content-Type: multipart/byteranges; boundary=String_separator

--String_separator
Content-Type: application/pdf
Content-Range: bytes 234-639/8000

...the first range...
--String_separator
Content-Type: application/pdf
Content-Range: bytes 4590-7999/8000

...the second range
--String_separator--

References

rdp commented 4 years ago

Kemal supports this (mostly). For interest: https://github.com/kemalcr/kemal/blob/18ddc3b4e6232ad7674d756c3d507da94398c7d6/src/kemal/helpers/helpers.cr#L184

636f7374 commented 4 years ago

@rdp Yes, but lack support for Several Range, and Crystal HTTP::StaticFileHandler should also support this feature. :)

636f7374 commented 4 years ago

@rdp Because it is more convenient to use HTTP::StaticFileHandler directly, low size. :)

asterite commented 4 years ago

It's so weird that they use skip in Kemal... can't they use file.pos = ...?

636f7374 commented 4 years ago

@asterite I think seek is better because other languages are implemented using seek. (Kemal maybe? ...)