GithubHelp home page GithubHelp logo

Comments (4)

Stadly avatar Stadly commented on June 5, 2024 1

To better illustrate the issue, here are a few examples:

Example of request and response for single byte range, where the entire file contents are abcdefghijklmnopqrstuvwxyz.

Request

GET /url/to/file HTTP/1.1
Range: bytes=5-15

Response

HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Length: 11
Content-Range: bytes 5-15/26

fghijklmnop

When emitting this response, SapiStreamEmitter will only emit klmnop as the body, since the first 5 bytes are omitted. SapiEmitter will emit the whole fghijklmnop.

Example of request and response for multiple byte ranges (the 4th byte, bytes 11 to 21, the last 5 bytes, bytes 19 and to the end), where the entire file contents are abcdefghijklmnopqrstuvwxyz.

Request

GET /url/to/file HTTP/1.1
Range: bytes=bytes=3-3, 10-20, -5, 18-

Response

HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Length: 227
Content-Type: multipart/byteranges; boundary=BOUNDARY

--BOUNDARY
Content-Range: bytes 3-3/26

d
--BOUNDARY
Content-Range: bytes 10-20/26

klmnopqrstu
--BOUNDARY
Content-Range: bytes 21-25/26

vwxyz
--BOUNDARY
Content-Range: bytes 18-25/26

stuvwxyz
--BOUNDARY--

When emitting this response, both SapiStreamEmitter and SapiEmitter will emit the whole response body, since there is no Content-Range header (it is embedded into the body for multi-range requests).

from http-emitter.

github-actions avatar github-actions commented on June 5, 2024

Awesome! Thank you for taking the time to create your first issue! Please review the guidelines

from http-emitter.

prisis avatar prisis commented on June 5, 2024

Thanks for you time to descript the issue, and i'm really sorry that i'm responding only right now.

I will try to come with a good solution, im happy if you have on too :)

from http-emitter.

Stadly avatar Stadly commented on June 5, 2024

After more consideration, I think the best solution is to fix the memory issue in SapiEmitter.

Is there a reason why SapiEmitter converts the whole response body to a string and emits it in a single go instead of emitting it as smaller chunks? With the current implementation of SapiEmitter, the entire response body must be written to memory, which does not work for large responses.

When the memory issue is fixed, SapiEmitter can be used when the application takes care of populating the response body correctly, and SapiStreamEmitter can be used to provide a simple support for single-range requests for bytes.

Alternative solutions are:

  1. Modify SapiStreamEmitter to allow ignoring the content range.
  2. Create a separate emitter. (It will function exactly like SapiEmitter, just without the memory issue, so that's the use?)

from http-emitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.