From 0337b78fef9346277686da6245ac377b77c0f180 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Sun, 29 Sep 2019 18:22:59 +0200 Subject: [PATCH] better/simpler accept-header handling --- includes/class-activitypub.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 8b3a54e..c6ffa04 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -54,17 +54,20 @@ class Activitypub { return $template; } - // interpret accept header - $pos = \stripos( $_SERVER['HTTP_ACCEPT'], ';' ); - if ( $pos ) { - $accept_header = \substr( $_SERVER['HTTP_ACCEPT'], 0, $pos ); - } else { - $accept_header = $_SERVER['HTTP_ACCEPT']; + $accept_header = $_SERVER['HTTP_ACCEPT']; + + if ( + stristr( $accept_header, 'application/activity+json' ) || + stristr( $accept_header, 'application/ld+json' ) + ) { + return $template; } + // accept header as an array $accept = \explode( ',', trim( $accept_header ) ); if ( + ! \in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) && ! \in_array( 'application/activity+json', $accept, true ) && ! \in_array( 'application/ld+json', $accept, true ) && ! \in_array( 'application/json', $accept, true )