From a14506c9dacc142f8d04547726f7a5950f9c56d9 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzmenkov Date: Mon, 28 Dec 2015 02:09:53 +0700 Subject: [PATCH] Autodetect response content type by default --- core/App.php | 5 +++++ skel/app/main.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/App.php b/core/App.php index 9d5e750..92017ef 100644 --- a/core/App.php +++ b/core/App.php @@ -124,23 +124,28 @@ public static function process(Request $Request, Response $Response) { switch (true) { case $response === 1: + $Response->header('Content-type', 'text/html;charset=utf-8'); return View::create($Request->getAction())->set($vars); break; case $response instanceof View: + $Response->header('Content-type', 'text/html;charset=utf-8'); return $response->set($vars); break; case is_string($response): + $Response->header('Content-type', 'text/plain;charset=utf-8'); return View::fromString($response); break; case is_array($response): case is_object($response): + $Response->header('Content-type', 'application/json;charset=utf-8'); return View::fromString(json_encode($response, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); break; default: + $Response->header('Content-type', 'text/plain;charset=utf-8'); return View::fromString((string) $response); } } diff --git a/skel/app/main.php b/skel/app/main.php index 93121f6..240d12e 100644 --- a/skel/app/main.php +++ b/skel/app/main.php @@ -1,7 +1,7 @@ header('Content-type', 'text/html;charset=utf-8'); +$Response = Response::create(200); $View = App::process(Request::create(), $Response) ->prepend('_head') ->append('_foot')