|
|
|
@ -8,43 +8,48 @@
|
|
|
|
|
// Standard Library
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
bool ap_object_handle_http_request( struct http_request* req, struct ap_object* obj, bool release, bool default_jsonld )
|
|
|
|
|
bool ap_object_handle_http_request_should_provide( struct http_request* req )
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
const char* accept_header = http_request_get_header( req, "Accept" );
|
|
|
|
|
const char* user_agent = http_request_get_header( req, "User-Agent" );
|
|
|
|
|
if( accept_header ) {
|
|
|
|
|
printf( "Accept: %s\n", accept_header );
|
|
|
|
|
if( strstr( accept_header, "application/ld+json" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if( strstr( accept_header, "application/json" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if( strstr( accept_header, "application/activity+json" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( user_agent ) {
|
|
|
|
|
printf( "User-Agent: %s\n", user_agent );
|
|
|
|
|
if( strstr( user_agent, "Pleroma" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if( strstr( user_agent, "Mastodon" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if( strstr( user_agent, "Akkoma" ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( default_jsonld ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ap_object_handle_http_request( struct http_request* req, struct ap_object* obj, bool release, bool default_jsonld )
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
if( ap_object_handle_http_request_should_provide( req ) ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
} else if( default_jsonld ) {
|
|
|
|
|
goto json_ld;
|
|
|
|
|
} else {
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
json_ld:
|
|
|
|
|
FILE* f = http_request_get_response_body( req );
|
|
|
|
|
http_request_add_header( req, "Access-Control-Allow-Origin", "*" );
|
|
|
|
|