Comments (4)
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.
Awesome! Thank you for taking the time to create your first issue! Please review the guidelines
from http-emitter.
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.
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:
- Modify
SapiStreamEmitter
to allow ignoring the content range. - 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)
- Close HTTP connections after emit HOT 4
- Disparity between SwooleEmitter and SapiEmitters? HOT 4
- Multi-byte string assumption in SapiStreamEmitter::emitBodyRange() ? HOT 12
- Caching issue HOT 4
- Move SwooleEmitter out of this package HOT 2
- Removing EmitterInterface
- Don't stream the entire response into memory HOT 3
- Dependabot can't resolve your PHP dependency files
- upgraded min php version to 7.2 and added php 7.4 to travis
- upgrade narrowspark/coding-standard to v3 and phpunit/phpunit to v8
- add connection_status check on while list
- add test for headers_sent exception
- Update composer.json to make it work with PHP8 HOT 4
- Dependency Dashboard HOT 1
- PHP Version 8.x compatibility HOT 2
- Stop PHP from overriding response header silently
- remove container-interop-implementation
- Add a comment when a headers already sent can happen
- Add a swoole emitter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-emitter.