Server isn’t sending content length [blog]

As part of the ZX Spectrum community I wrote a tool that can download content over HTTP from a ZX Spectrum Next, but one prerequisite is that the content-length header is present (so it operate properly).
A friend from the community runs a server and built a (really nice) GUI tool on top the .http command where users can find and download software for their Spectrum.
However, for reasons unknown, it wasn’t working and content-length just seemed to be missing.
This fix isn’t Speccy specific, it will fix missing content length for Apache 2 servers.


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log

As part of the ZX Spectrum community I wrote a tool that can download content over HTTP from a ZX Spectrum Next, but one prerequisite is that the content-length header is present (so it operate properly).

A friend from the community runs a server and built a (really nice) GUI tool on top the .http command where users can find and download software for their Spectrum.

However, for reasons unknown, it wasn't working and content-length just seemed to be missing.

This fix isn't Speccy specific, it will fix missing content length for Apache 2 servers.

Testing

Even though the content-length was being set in the PHP files, by default, Apache was configured to chunk encoding (which is generally prefer, by the server, when sending dynamic based content, i.e. content generated by a PHP file).

So somewhere the content-length was being stripped.

This is all tested using a curl command with the -i flag to include headers:

$ curl -i example.com

Though this does include the full body, so it's easier to debug using -I (which requests the headers via a HEAD request) but the HEAD request is not equal to GET so we'll explicitly call a GET using -X:

$ curl -I -X GET example.com

Now we just have the headers and we can check if anything is missing.

A note about debugging with browser tools: browsers are going to augment the "raw" request. Firstly you have caching in play (so fire up the privacy window and disable caching from the network panel), but also they show you how they interpreted the headers.

This is Firefox for instance on https://www.google.com:

Firefox GET request headers panel

Whereas if we tick that "raw" checkbox, we can see the content-length was never part of the headers:

Firefox raw headers

Chrome will also add the header (with no option for the original response) but show it as a content length of zero.

So, make sure you're testing as close to the metal as possible.

Fixing

At some point (in Apache's history), a change was made to prevent scripts from setting certain headers (in particular content-length) to mitigate potential vulnerabilities.

So to trust your scripts, an apache rule is required to apply this. The follow example solved our particular problem, including the change in an .htaccess file in the root of the directory being served:

<Files *.php>
  SetEnv ap_trust_cgilike_cl 1
</Files>

Now Apache will trust all the headers, content-length specifically, from the PHP files.

Originally published on Remy Sharp's b:log


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log


Print Share Comment Cite Upload Translate Updates
APA

remy sharp's b:log | Sciencx (2025-01-03T00:00:00+00:00) Server isn’t sending content length [blog]. Retrieved from https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/

MLA
" » Server isn’t sending content length [blog]." remy sharp's b:log | Sciencx - Friday January 3, 2025, https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/
HARVARD
remy sharp's b:log | Sciencx Friday January 3, 2025 » Server isn’t sending content length [blog]., viewed ,<https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/>
VANCOUVER
remy sharp's b:log | Sciencx - » Server isn’t sending content length [blog]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/
CHICAGO
" » Server isn’t sending content length [blog]." remy sharp's b:log | Sciencx - Accessed . https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/
IEEE
" » Server isn’t sending content length [blog]." remy sharp's b:log | Sciencx [Online]. Available: https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/. [Accessed: ]
rf:citation
» Server isn’t sending content length [blog] | remy sharp's b:log | Sciencx | https://www.scien.cx/2025/01/03/server-isnt-sending-content-length-blog/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.