-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
SapiStreamEmitter that does not consider Content-Range #22
Comments
Sounds interesting but I actually don't have a use-case for this while not fully understanding the standard on how to implement multi-range responses at all. Due to this fact, I am unsure if Since the Maybe there are other @laminas/technical-steering-committee members which have a deeper knowledge regarding this specific details (multi-range, non-bytes, ...). I guess this provides some technical details: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests |
The idea behind the As to why it's implemented the way it is: it's primarily to work with the way PSR-7 defines content body, which is as streams. The default implementation we provide in Diactoros is backed by a PHP stream, which can either be an in-memory resource (e.g., Because of the way the The point is that your middleware and handlers can determine what the user has requested via the headers, and offload how that range is returned to the stream implementation itself, versus doing that heavy lifting directly. If you don't like this particular approach, omit the |
I came across the issue while creating the file serving library FileWaiter. Example of request and response for single byte range, where the entire file contents are 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, 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 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 |
This is very nice, aside from the fact that it will only give the expected output if all the conditions are met: single range, byte unit, seekable. If any of the conditions are not met, the entire body will be output. Therefore, it makes more sense to populate the correct response body when generating the response than when emitting it. Then it is clear who is responsible for what, and the responsibilities will always be the same - not depend on some condition (single range, byte unit, seekable).
This can also be done when populating only a range of a file into a response body, for instance using LimitStream - there is no need to do it during emit to get the performance benefit.
The problem then is that you end up with |
We're well aware that not all emitters will work for all use cases, which is why the |
Feature Request
Summary
SapiStreamEmitter::emit
considers the headerContent-Range
and emits only the relevant range when only a single range is requested and the range unit isbytes
. This seems very nice and convenient at first glance.If the application wants to support multi-range requests or range units other than
bytes
, however, populating the response with the correct content range(s) must be done by the application, andSapiStreamEmitter
will emit the entire provided response body.This seems very asymmetrical to me. Who should actually be in charge of ensuring that the response body is correct? The one who populates the response body or the one who emits it?
My application would have to populate the final response body in the case of multi-range or non-byte unit, but populate the entire file into the response body in the case of single byte range, and then let
SapiStreamEmitter
handle the range-stuff. I would like the option to letSapiStreamEmitter
just output the whole response body that I have provided, regardless of theContent-Range
range header.I actually don't think the
Content-Range
functionality has anything to do in the emitter, so I would prefer to just remove it. But such a change in functionality might warrant a new major version. The behavior could also be set in a constructor argument. Or there could be a separate class.If the
Content-Range
functionality has anything to do in the emitter, why isn't it also a part of theSapiEmitter
. In my opinion, exchanging the one for the other should not lead to different output.The text was updated successfully, but these errors were encountered: