Remove accept_contains_mime, as it's unstable

This commit is contained in:
Starbeamrainbowlabs 2018-04-06 23:54:57 +01:00
parent 7a243215ec
commit 81cd1ad871
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
4 changed files with 1 additions and 63 deletions

View File

@ -935,29 +935,6 @@ function system_extension_mime_type($ext) {
$ext = strtolower($ext);
return isset($types[$ext]) ? $types[$ext] : null;
}
/**
* Figures out whether a given http accepts header contains a
* specified mime type.
* @package core
* @param string $accept_header The accept header to search.
* @param string $mime_type The mime type to search for.
* @return bool Whether the specified mime type was found
* in the specified accepts header.
*/
function accept_contains_mime($accept_header, $mime_type)
{
$target_mime = explode("/", $mime_type);
$accepted_mimes = explode(",", $accept_header);
foreach($accepted_mimes as $accepted_mime) {
$next_mime = explode("/", explode(";", $accepted_mime)[0]);
if($next_mime == $mime_type || ($next_mime[0] == "*" && $next_mime[1] == "*"))
return true;
if($next_mime[1] == "*" && $next_mime[0] == $mime_type[0])
return true;
}
return false;
}
/**
* Generates a stack trace.
@ -2381,14 +2358,6 @@ register_module([
add_action("status", function() {
global $version, $env, $settings, $actions;
// Make sure the client can accept JSON
if(!accept_contains_mime($_SERVER["HTTP_ACCEPT"] ?? "application/json", "application/json")) {
http_response_code(406);
header("content-type: text/plain");
exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
}
$minified = ($_GET["minified"] ?? "false") == "true";
$action_names = array_keys(get_object_vars($actions));

View File

@ -558,29 +558,6 @@ function system_extension_mime_type($ext) {
$ext = strtolower($ext);
return isset($types[$ext]) ? $types[$ext] : null;
}
/**
* Figures out whether a given http accepts header contains a
* specified mime type.
* @package core
* @param string $accept_header The accept header to search.
* @param string $mime_type The mime type to search for.
* @return bool Whether the specified mime type was found
* in the specified accepts header.
*/
function accept_contains_mime($accept_header, $mime_type)
{
$target_mime = explode("/", $mime_type);
$accepted_mimes = explode(",", $accept_header);
foreach($accepted_mimes as $accepted_mime) {
$next_mime = explode("/", explode(";", $accepted_mime)[0]);
if($next_mime == $mime_type || ($next_mime[0] == "*" && $next_mime[1] == "*"))
return true;
if($next_mime[1] == "*" && $next_mime[0] == $mime_type[0])
return true;
}
return false;
}
/**
* Generates a stack trace.

View File

@ -41,7 +41,7 @@
"author": "Starbeamrainbowlabs",
"description": "Provides a basic JSON status action that provices a few useful bits of information for API consumption.",
"id": "api-status",
"lastupdate": 1522689976,
"lastupdate": 1523055259,
"optional": false
},
{

View File

@ -20,14 +20,6 @@ register_module([
add_action("status", function() {
global $version, $env, $settings, $actions;
// Make sure the client can accept JSON
if(!accept_contains_mime($_SERVER["HTTP_ACCEPT"] ?? "application/json", "application/json")) {
http_response_code(406);
header("content-type: text/plain");
exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
}
$minified = ($_GET["minified"] ?? "false") == "true";
$action_names = array_keys(get_object_vars($actions));