Closed juansebasleal closed 3 years ago
Hi @juansebasleal - can you explain why it is actually not valid and provide an example ?
Hi @specialtactics
Well, if the response has not actual body (HTTP 204 response), it should not have Content-Type because there's no content.
The example would be easy to setup: In any controller just respond with DingoResponse->noContent().
Also, here you can see an example of how we get Content-Type: (null)
What I think is that it happens because in api/src/Http/Response.php, method morph(), $formatter->getContentType() is null.
Additionally, this is more evident when we use a validator, in this case https://github.com/Nyholm/psr7, and we see that in fact it fails because of what was said above.
My environment: Laravel: 5.7.15 Dingo: 2.0.1 Validator: 1.3.0
Hopefully this helps clarify the issue.
Hey @juansebasleal thanks, that was quite detailed.
I believe I've fixed the issue now, you can try the latest master if you like to confirm, it will be tagged before too long but there are also other changes there for testing.
In a Laravel Controller, I am returning
$this->response->noContent()
, which returns a Dingo Response. Then, I'm running a validator on the response and I'm getting the following error:I see what is causing it is:
in the
Dingo\Api\Http\Response::morph()
method https://github.com/dingo/api/blob/42c5b78d010fbd97dc73aa01b259f05b1f033ce6/src/Http/Response.php#L145I think there should be a validation:
if ($formatter->getContentType()) { // Add content type }
Our current Dingo version is 2.0.1
Thanks.