From 80a33662949cf1ef2bee70289489d3f7daa60a2b Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 7 Aug 2014 14:52:59 +0200 Subject: [PATCH] Fix api content type --- lib/Alchemy/Phrasea/Application/Api.php | 6 ++++-- lib/Alchemy/Phrasea/Controller/Api/Oauth2.php | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index 0f1a33ca32..3c98680157 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -48,7 +48,7 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $request->setFormat(\API_V1_result::FORMAT_JSONP, array('text/javascript', 'application/javascript')); // handle content negociation - $priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript', 'text/html'); + $priorities = array('application/json', 'application/yaml', 'text/yaml', 'text/javascript', 'application/javascript'); foreach (\API_V1_adapter::$extendedContentTypes['json'] as $priorities[]); foreach (\API_V1_adapter::$extendedContentTypes['yaml'] as $priorities[]); $format = $app['format.negociator']->getBest($request->headers->get('accept') ,$priorities); @@ -80,7 +80,9 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) { $response->setStatusCode(200); } // set response content type - $response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(\API_V1_result::FORMAT_JSON))); + if (!$response->headers->get('Content-Type')) { + $response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(\API_V1_result::FORMAT_JSON))); + } }); $app->register(new \API_V1_Timer()); diff --git a/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php b/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php index 4d80b28015..f6c6aa546f 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php +++ b/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php @@ -90,7 +90,10 @@ class Oauth2 implements ControllerProviderInterface $app['authentication']->openAccount(\User_Adapter::getInstance($usr_id, $app)); } else { - return new Response($app['twig']->render($template, array('error' => $error, "auth" => $oauth2_adapter))); + $r = new Response($app['twig']->render($template, array('error' => $error, "auth" => $oauth2_adapter))); + $r->headers->set('Content-Type', 'text/html'); + + return $r; } } @@ -115,7 +118,10 @@ class Oauth2 implements ControllerProviderInterface "error" => $error, ); - return new Response($app['twig']->render($template, $params)); + $r = new Response($app['twig']->render($template, $params)); + $r->headers->set('Content-Type', 'text/html'); + + return $r; } elseif (!$app_authorized && $action_accept !== null) { $app_authorized = (Boolean) $action_accept; $account->set_revoked(!$app_authorized); @@ -125,7 +131,10 @@ class Oauth2 implements ControllerProviderInterface if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) { $params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params); - return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params)); + $r = new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params)); + $r->headers->set('Content-Type', 'text/html'); + + return $r; } $oauth2_adapter->finishClientAuthorization($app_authorized, $params);