You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid Content-Length header added when body size is unknown #327
When response body has unknown size, an empty Content-Length header is added, which is invalid.
RFC2616 states:
Any Content-Length greater than or equal to zero is a valid value.
And StreamInterface says:
/** * Get the size of the stream if known. * * @return int|null Returns the size in bytes if known, or null if unknown. */publicfunctiongetSize();
In StreamingServer.php, (string)$body->getSize() should be checked before inserting the header:
elseif (!$bodyinstanceof HttpBodyStream) {
// assign Content-Length header when using a "normal" buffered body string$response = $response->withHeader('Content-Length', (string)$body->getSize())->withoutHeader('Transfer-Encoding');
}
changed the title [-]Invalid Content-Length header added when body size is inknown[/-][+]Invalid Content-Length header added when body size is unknown[/+]on Nov 11, 2018
@phpbg Thanks for reporting, I understand where you're coming from!
This project does follow HTTP specs and adds these headers automatically under certain circumstances. In this instance, it looks like there's indeed a small defect when not using the built-in Response class but a third-party one that does indeed follow valid PSR-7 semantics but does not behave as this library expects.
That being said, it looks like this may not be cause of the issue you're seeing. In your case, it sounds like you want to stream a response body. This project being an event-driven, non-blocking implementation and PSR-7 being a definition for synchronous environments means we've had to implement a number of work-arounds that result in some known limitations. If you want to return a streaming response, this will have to be wrapped in a ReadableStreamInterface. This should be covered in the documentation: https://github.com/reactphp/http#streaming-response
Activity
[-]Invalid Content-Length header added when body size is inknown[/-][+]Invalid Content-Length header added when body size is unknown[/+]WyriHaximus commentedon Nov 11, 2018
As always we're open for PR's fixing bugs like these. Would you be interested in doing that?
clue commentedon Nov 12, 2018
@phpbg Thanks for reporting, I understand where you're coming from!
This project does follow HTTP specs and adds these headers automatically under certain circumstances. In this instance, it looks like there's indeed a small defect when not using the built-in
Responseclass but a third-party one that does indeed follow valid PSR-7 semantics but does not behave as this library expects.That being said, it looks like this may not be cause of the issue you're seeing. In your case, it sounds like you want to stream a response body. This project being an event-driven, non-blocking implementation and PSR-7 being a definition for synchronous environments means we've had to implement a number of work-arounds that result in some known limitations. If you want to return a streaming response, this will have to be wrapped in a
ReadableStreamInterface. This should be covered in the documentation: https://github.com/reactphp/http#streaming-responsephpbg commentedon Nov 12, 2018
You were too fast doing the PR :-)