Content-length incorrect and response truncated in web servers

Created on 22 March 2024, 9 months ago
Updated 24 July 2024, 5 months ago

Using the rest api (bat_api) the response json is truncated and therefore the json is not valid.

This happens only since Drupal 10.2 I understand because of this change:
https://www.drupal.org/node/3298551 β†’

This is truncated because the Content-length header is returned with the length value of the response content.

This is done in the
web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php

on line 48:
$response->headers->set('Content-Length', strlen($content), TRUE);

Actually the content length gets it right, it is correct, but then nginx for some reason cuts it 2 characters before. Maybe it is that the final content is 2 characters bigger, but I have not been able to find out at the moment.

As a temporary solution I have created this MR where I only add 2 more characters:
$response->headers->set('Content-Length', strlen($content)+2, TRUE);

And also to see if more people have the same problem and if so, let's see if we can find a real solution between all of us.

To summarize: Without this MR the json response is cut off and is not valid and with the MR it is correct.

πŸ› Bug report
Status

Closed: won't fix

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain Carlitus

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024