thephpleague / booboo

A modern error handler capable of logging and formatting errors in a variety of ways.
MIT License
338 stars 25 forks source link

Formatters should include a Content-Type #21

Open shadowhand opened 9 years ago

shadowhand commented 9 years ago

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;
sergeyklay commented 9 years ago

:+1:

ghost commented 9 years ago

:+1:

brandonsavage commented 7 years ago

This won't work.

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

shadowhand commented 7 years ago

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

brandonsavage commented 7 years ago

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.

shadowhand commented 7 years ago

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