Slim.php 带有代码 304 的 `halt` 方法不打印响应正文

Slim.php `halt` method with code 304 does not print response body

当我调用 $app->halt(200, "Lorem ipsum"); 或 304 以外的任何其他状态代码时,它会以正确的状态代码进行响应并打印出正文。但是使用相同的代码,只是将 200 更改为 304 $app->halt(304, "Lorem ipsum");,返回的状态代码为 304,但主体为空。

导致此问题的原因可能是什么?如何打印响应代码为 304 的响应正文?

您不能拥有带有 304 的正文。根据规范

10.3.5 304 Not Modified

If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code. The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.