Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

assert_content_type()

Description

Assert API sent the expected content type.

Parameters

ColumnTypeDefaultDescription
$expected string MIME type
$received_raw: string
$received_raw string MIME type

Return

array Returns JSend data back {@see ajax_functions.php} if received Content-Type is unexpected

Location

include/api_functions.php lines 295 to 313

Definition

 
function assert_content_type(string $expectedstring $received_raw): array
    {
    
$expected trim($expected);
    if (
$expected === '')
        {
        
trigger_error('Expected MIME type MUST not be a blank string'E_USER_ERROR);
        }

    
$encoding 'UTF-8';
    
$received mb_strcut($received_raw0mb_strlen($expected$encoding), $encoding);
    if (
$expected === $received)
        {
        return [];
        }

    
http_response_code(415);
    
header("Accept: {$expected}");
    return 
ajax_response_fail([]);
    }

This article was last updated 27th April 2024 12:05 Europe/London time based on the source file dated 25th April 2024 17:25 Europe/London time.