Skip to content

Commit 0337b78

Browse files
committed
better/simpler accept-header handling
1 parent 9fd551f commit 0337b78

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

includes/class-activitypub.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ public static function render_json_template( $template ) {
5454
return $template;
5555
}
5656

57-
// interpret accept header
58-
$pos = \stripos( $_SERVER['HTTP_ACCEPT'], ';' );
59-
if ( $pos ) {
60-
$accept_header = \substr( $_SERVER['HTTP_ACCEPT'], 0, $pos );
61-
} else {
62-
$accept_header = $_SERVER['HTTP_ACCEPT'];
57+
$accept_header = $_SERVER['HTTP_ACCEPT'];
58+
59+
if (
60+
stristr( $accept_header, 'application/activity+json' ) ||
61+
stristr( $accept_header, 'application/ld+json' )
62+
) {
63+
return $template;
6364
}
65+
6466
// accept header as an array
6567
$accept = \explode( ',', trim( $accept_header ) );
6668

6769
if (
70+
! \in_array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', $accept, true ) &&
6871
! \in_array( 'application/activity+json', $accept, true ) &&
6972
! \in_array( 'application/ld+json', $accept, true ) &&
7073
! \in_array( 'application/json', $accept, true )

0 commit comments

Comments
 (0)