Tuesday 9 April 2024

http range request, curl range header,

 http by default allows partial request, so browser/curl can resume download when using range header



to see if server allows partial transmission of data :

https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

BASH
curl -I http://i.imgur.com/z4d4kWk.jpg
HTTP
HTTP/1.1 200 OKAccept-Ranges: bytes
Content-Length: 146515
If server response Accept-Ranges: byte, then server accepts partial
For GO gin, c.FileAttachement enable or r.static at router level enables range
https://pkg.go.dev/github.com/gin-gonic/gin#Context.File
func (c *Context) FileAttachment(filepath, filename string)

for curl you can request range 

https://everything.curl.dev/http/ranges.html

For browser set up for resumable download visit:
https://stackoverflow.com/questions/38200426/detecting-when-the-browser-has-requested-to-download-a-file

Each time you will get some content  and http response 206
The HTTP 206 Partial Content success status response code indicates that the request has succeeded and the body contains the requested ranges of data, as described in the Range header of the request.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206
curl -r 0-199 http://example.com

Or everything in the file starting from index 200:

curl -r 200- http://example.com

Get 200 bytes from index 0 and 200 bytes from index 1000:

curl -r 0-199,1000-1199 http://example.com/

No comments:

Post a Comment