Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 8th December 2024 10:05 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.