Comments (4)
That's a great catch; I think it should be the job of the emitter, to be honest. Considering the information is in the response stream already (via getSize()
), it could be something like this:
if (! $response->hasHeader('Content-Length')) {
$response = $response->withHeader('Content-Length', $response->getBody()->getSize());
}
That could even be provided as a trait method (e.g., injectContentLength(ResponseInterface $response): ResponseInterface
), which emitters can then compose in order to provide this functionality.
Want to give it a whirl, @mnapoli ?
from zend-diactoros.
Great, that will also simplify my code. It's on my todo list then!
from zend-diactoros.
This was fixed by #88.
from zend-diactoros.
@mnapoli @weierophinney A little late to the game, but why exactly was this added? AFAIK, Content-Length
is only needed for downloads.
I am asking because we have some issue reports about truncated JSON responses for Flarum which seem to have to do with this header not matching the true content length.
EDIT: Fixed the issue link.
from zend-diactoros.
Related Issues (20)
- Return types inaccurate HOT 5
- ServerRequest: Header with value "0" discarded HOT 6
- Segfault in PHP 7.3.0 when instantiating HtmlResponse in Built-in Web Server HOT 13
- Version 2.0.2 breaks on Apache HOT 5
- get an exeption from ServerRequestFactory::fromGlobals if i make get req without variables HOT 4
- Header error with Docker container usage HOT 12
- ServerRequestFactory::fromGlobals() breaking on windows x64 HOT 3
- UTF-8 URIs are broken by parse_url when locale is set HOT 6
- Empty header check breaking change HOT 4
- Uncaught TypeError: Return value of Zend\\Diactoros\\Uri::filterQueryOrFragment() must be of the type string, null returned HOT 7
- Array cookies not parser properly HOT 1
- marshallHttps incorrectly detects HTtPS-connection
- Generators are not supported for JSON responses. HOT 1
- BUG: marshalHeadersFromSapi assume all SERVER keys are strings HOT 1
- LTS Version 1.7 is missing a security fix HOT 5
- PHP Parse error: syntax error, unexpected '?', expecting variable @ marshal_uri_from_sapi.php on line 83 HOT 7
- Can UploadedFile extend SplFileInfo ? HOT 12
- PhpInputStream's getSize function is Wrong! HOT 4
- Probably an incorrect test case testAuthorityIsPrefixedByDoubleSlashIfPresent in UriTest.php HOT 1
- PHP Fatal error: require(): Failed opening required zendframework/zend-diactoros/src/functions/create_uploaded_file.php HOT 4
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 zend-diactoros.