Drupal\Core\Routing\ContentTypeHeaderMatcher checks $request->headers->has('Content-type') to decide which error message to show if the content type header does not match any route.
Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::testPost() (and all test classes that inherit this) verify this behavior by sending a request without a content-type header.
However, some webserver environments (this occurs in nginx with fastcgi) appear to default this header to an empty value if the client does not send it.
In this case, has(...) will return true even though the header is empty, and the wrong exception will be thrown.
The solution would be to not call has(), but instead check if the content-type header is empty.
Comment | File | Size | Author |
---|---|---|---|
#4 | drupal-rest-2860913-4.patch | 785 bytes | cburschka |
#2 | drupal-rest-2860913-2.patch | 754 bytes | cburschka |
Comments
Comment #2
cburschkaComment #4
cburschkaOkay, it looks like getContentType() has extra logic beyond checking the header. Then replace the has() call with a get() call instead.
Comment #6
cburschkaRetesting.
Comment #7
cburschkaAlso, I rather suspect this is still okay for 8.4.x.
Comment #8
cburschkaComment #9
cburschkaComment #12
mr.baileysI can confirm this issue after spending a debugging a test that was failing on my local environment (ddev, nginx+fastcgi). The test kept failing with:
After applying the patch in #4 (patch still applies cleanly against 8.9.x-dev), the test came back green.
The fix looks sane to me, although:
\Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testContentTypeRequestHeaderMissing
so it includes a request with an empty (but present) Content-Type header;Nitpick, but the exception message should become 'Empty or no "Content-Type" request header specified' or something along those lines?
Comment #13
mr.baileysThis was also reported and fixed in #3090626: ContentTypeHeaderMatcher dx tests broken with some nginx configs