booboo icon indicating copy to clipboard operation
booboo copied to clipboard

Formatters should include a Content-Type

Open shadowhand opened this issue 10 years ago • 6 comments

Formatters should also do something like this:

// JsonFormatter
public function getContentType()
{
    return 'application/json';
}

So that when the formatted output is returned, the appropriate type can be set:

// Runner
list ($mime, $body) = $this->runFormatters($e);
header('Content-Type: ' . $mime);
echo $body;

shadowhand avatar Mar 30 '15 20:03 shadowhand

:+1:

sergeyklay avatar Mar 31 '15 19:03 sergeyklay

:+1:

ghost avatar Apr 19 '15 10:04 ghost

This won't work.

Any time the headers have already been sent, this will produce another error, creating an endless loop.

brandonsavage avatar Feb 01 '17 03:02 brandonsavage

@brandonsavage that can be changed. The formatted response can be generated before printing any output or sending headers.

shadowhand avatar Feb 25 '17 16:02 shadowhand

Suppose somebody is writing an application, and in their template, halfway through rendering the page, they reference a variable that is not in scope. They trigger a notice. Under this scheme we'll attempt to send headers back when headers have already been sent. That simply won't end well.

brandonsavage avatar Jul 07 '17 22:07 brandonsavage

@brandonsavage that could happen but I think it is fairly uncommon practice to not have output buffering in place.

shadowhand avatar Jul 07 '17 22:07 shadowhand