mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Remove accept_contains_mime, as it's unstable
This commit is contained in:
parent
7a243215ec
commit
81cd1ad871
4 changed files with 1 additions and 63 deletions
|
@ -935,29 +935,6 @@ function system_extension_mime_type($ext) {
|
||||||
$ext = strtolower($ext);
|
$ext = strtolower($ext);
|
||||||
return isset($types[$ext]) ? $types[$ext] : null;
|
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.
|
* Generates a stack trace.
|
||||||
|
@ -2381,14 +2358,6 @@ register_module([
|
||||||
add_action("status", function() {
|
add_action("status", function() {
|
||||||
global $version, $env, $settings, $actions;
|
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";
|
$minified = ($_GET["minified"] ?? "false") == "true";
|
||||||
|
|
||||||
$action_names = array_keys(get_object_vars($actions));
|
$action_names = array_keys(get_object_vars($actions));
|
||||||
|
|
23
core.php
23
core.php
|
@ -558,29 +558,6 @@ function system_extension_mime_type($ext) {
|
||||||
$ext = strtolower($ext);
|
$ext = strtolower($ext);
|
||||||
return isset($types[$ext]) ? $types[$ext] : null;
|
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.
|
* Generates a stack trace.
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Provides a basic JSON status action that provices a few useful bits of information for API consumption.",
|
"description": "Provides a basic JSON status action that provices a few useful bits of information for API consumption.",
|
||||||
"id": "api-status",
|
"id": "api-status",
|
||||||
"lastupdate": 1522689976,
|
"lastupdate": 1523055259,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,14 +20,6 @@ register_module([
|
||||||
add_action("status", function() {
|
add_action("status", function() {
|
||||||
global $version, $env, $settings, $actions;
|
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";
|
$minified = ($_GET["minified"] ?? "false") == "true";
|
||||||
|
|
||||||
$action_names = array_keys(get_object_vars($actions));
|
$action_names = array_keys(get_object_vars($actions));
|
||||||
|
|
Loading…
Reference in a new issue