Skip to content
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

🤗 [Question]: How to handle multipart range request? #2844

Closed
3 tasks done
sergey-ust opened this issue Feb 10, 2024 · 5 comments
Closed
3 tasks done

🤗 [Question]: How to handle multipart range request? #2844

sergey-ust opened this issue Feb 10, 2024 · 5 comments

Comments

@sergey-ust
Copy link

Question Description

I'm struggling with responding on such multipart range requests like in mozila.org example

Maybe someone could give me a clue how to construct a response like that (mozila.org example):

HTTP/1.1 206 Partial Content
Content-Type: multipart/byteranges; boundary=3d6b6a416f9b5
Content-Length: 282

--3d6b6a416f9b5
Content-Type: text/html
Content-Range: bytes 0-50/1270

<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Example Do
--3d6b6a416f9b5
Content-Type: text/html
Content-Range: bytes 100-150/1270

eta http-equiv="Content-type" content="text/html; c
--3d6b6a416f9b5--

Thank you in advance

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
Copy link

welcome bot commented Feb 10, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@sergey-ust sergey-ust changed the title 🤗 [Question]: How to handle multipart range request 🤗 [Question]: How to handle multipart range request? Feb 10, 2024
@ReneWerner87
Copy link
Member

what do you want to achieve? do you want to send a file?

https://docs.gofiber.io/api/middleware/filesystem#sendfile supports partial content transfer

@sergey-ust
Copy link
Author

Firstly, @ReneWerner87 thanks a lot for your answer!

I want to return some file parts in the response and unfortunately I don't have a real file, only io.Reader interface. I can obtain such io.Reader object from my storage by call something like: payloadReader := storage.StartDownload(offset, bytesCnt). And I have found a way to fill the request body with interfaces and without additional copying:

	io.Copy(ctx.Response().BodyWriter(), payloadReader)

How can I see, it's possible to construct the multipart range response with manually adding into the response body the following parts:

  1. a boundary (=separator)
  2. part headers
  3. data (copying with interfaces)

But maybe there are some corresponding methods, aren't they?

@ReneWerner87
Copy link
Member

thats a little bit harder

you have to follow the following approach
https://github.com/valyala/fasthttp/blob/bce576699a322ab33b618773a4456a25e602682d/http_test.go#L1540C2-L1540C10

@sergey-ust
Copy link
Author

thanks a lot!

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

No branches or pull requests

2 participants