Merge pull request #1132 from nlegoff/fix-api-content-type

[3.8.6] Fix api content type
This commit is contained in:
Nicolas Le Goff
2014-08-07 17:48:41 +02:00
2 changed files with 16 additions and 5 deletions

View File

@@ -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());

View File

@@ -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);