Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Formatters should include a Content-Type #21

Open
shadowhand opened this issue Mar 30, 2015 · 6 comments
Open

Formatters should include a Content-Type #21

shadowhand opened this issue Mar 30, 2015 · 6 comments

Comments

@shadowhand
Copy link
Member

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 shadowhand changed the title Formatting should include a Content-Type Formatters should include a Content-Type Mar 30, 2015
@sergeyklay
Copy link

👍

1 similar comment
@ghost
Copy link

ghost commented Apr 19, 2015

👍

@brandonsavage
Copy link
Contributor

This won't work.

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

@shadowhand
Copy link
Member Author

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

@brandonsavage
Copy link
Contributor

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
Copy link
Member Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants