Problem/Motivation
#3295790: Post-response task running (destructable services) are actually blocking; add test coverage and warn for common misconfiguration adds a content-length header to most responses coming from Drupal. It needs to be adjust due the expectations laid in https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length. Among these are:
- For HEAD requests content-length should be equal to the equivalent GET request - tested this and it works so that's good.
- 1xx and 204 cannot have a content length header
- 304s has a complex rule about being the same as a 200
Also there are some other things we should account for based on the issues we had when Symfony set a content-length header on everything. See https://github.com/symfony/symfony/issues/46449.
- No content-length header when the transfer-encoding header is set.
- No content-length header when $response->getContent() returns FALSE.
Lastly we should not add the header to 500s as this causes issues with if there is an error during batch processing.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3396559-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3396559
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3396559-only-set-content-length
changes, plain diff MR !5121
Comments
Comment #3
alexpottThis changes the method to look like this:
Some of this is inspired by what's in \Symfony\Component\HttpFoundation\Response::prepare() which is the last thing called by \Drupal\Core\DrupalKernel::handle() before we send the request.
So as it turns out Symfony is already fixing quite a bit of this for us, but I still think we shouldn't be adding this header in when we know we're just going to remove it later.
One thing I wonder is just we remove
as this is covered by
Comment #4
andypostCurious how it will work when gzip/brotli will be enabled at web-server side
Comment #5
alexpott@andypost how is that relevant to this issue? Do they require the content-length header? FWIW server side gzip/brotli must adjust the content-length header - as suggested here https://serverfault.com/questions/783029/apache-returns-invalid-content-...
Comment #6
catchYes this makes sense, as evidenced by having to get to this issue to find this out. Removing the explicit StreamedResponse check seems fine, if that somehow changes later, we'll find out.
Comment #7
alexpottI'm thinking that we should separate out the isServerError() check as that's the one thing that's not per RFC but down to some oddness in Drupal's error handling. Then if we fix that we could remove it. Pushed that change to the MR.
Comment #8
alexpottComment #9
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #10
catchLooks like #3409885: Uncaught ajax.js error / exception is reporting this too.
Comment #11
catchThere's one case in #3409885-15: Uncaught ajax.js error / exception that this won't fix, but it's not clear to me how they ended up in that situation. Given that, I think we should go ahead here to at least now the failure cases down more.
Comment #12
catchI only pushed the rebase button to get the MR green again. This looks fine to me and I think we should go ahead.
Comment #13
larowlanComment #14
larowlanIssue credits
Comment #17
larowlanCommitted to 11.x and backported to 10.2.x
Thought about asking for a test-case with StreamedResponse with a callback, but then realized StreamedResponse::getContent returns FALSE so it doesn't matter.
Thanks all
Comment #19
mstrelan commentedThis seems to have introduced a new test class with a typo, we now have
FinishResponseSubscriberTestandFinishResponserSubscriberTest. Should this be reverted and we merge these together?Comment #20
larowlan#3410022: Regression from #3295790 content-length header set earlier than expected deletes that test and is also critical
Should we focus effort there?