Skip to content

Commit b946ef3

Browse files
authored
more consistent use of response content type (#529)
* more consistent use of response content type * update readme * fix typo
1 parent 9ac5d84 commit b946ef3

File tree

9 files changed

+40
-26
lines changed

9 files changed

+40
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
114114
* Improved: loading of shortcodes
115115
* Updated: caching of followers
116116
* Updated: Application-User is no longer "indexable"
117+
* Updated: more consistent usage of the `application/activity+json` Content-Type
117118

118119
### 1.0.7 ###
119120

includes/rest/class-collection.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public static function tags_get( $request ) {
117117
);
118118
}
119119

120-
return new WP_REST_Response( $response, 200 );
120+
$rest_response = new WP_REST_Response( $response, 200 );
121+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
122+
123+
return $rest_response;
121124
}
122125

123126
/**
@@ -168,7 +171,10 @@ public static function featured_get( $request ) {
168171
$response['orderedItems'][] = Post::transform( $post )->to_object()->to_array();
169172
}
170173

171-
return new WP_REST_Response( $response, 200 );
174+
$rest_response = new WP_REST_Response( $response, 200 );
175+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
176+
177+
return $rest_response;
172178
}
173179

174180
/**
@@ -192,7 +198,10 @@ public static function moderators_get( $request ) {
192198
$response['orderedItems'][] = $user->get_url();
193199
}
194200

195-
return new WP_REST_Response( $response, 200 );
201+
$rest_response = new WP_REST_Response( $response, 200 );
202+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
203+
204+
return $rest_response;
196205
}
197206

198207
/**

includes/rest/class-followers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ function( $item ) use ( $context ) {
103103
$data['followers']
104104
);
105105

106-
$response = new WP_REST_Response( $json, 200 );
107-
$response->header( 'Content-Type', 'application/activity+json' );
106+
$rest_response = new WP_REST_Response( $json, 200 );
107+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
108108

109-
return $response;
109+
return $rest_response;
110110
}
111111

112112
/**

includes/rest/class-following.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public static function get( $request ) {
7979

8080
$json->first = $json->partOf; // phpcs:ignore
8181

82-
$response = new \WP_REST_Response( $json, 200 );
83-
$response->header( 'Content-Type', 'application/activity+json' );
82+
$rest_response = new WP_REST_Response( $json, 200 );
83+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
8484

85-
return $response;
85+
return $rest_response;
8686
}
8787

8888
/**

includes/rest/class-inbox.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ public static function user_inbox_get( $request ) {
109109
*/
110110
\do_action( 'activitypub_inbox_post' );
111111

112-
$response = new WP_REST_Response( $json, 200 );
112+
$rest_response = new WP_REST_Response( $json, 200 );
113+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
113114

114-
$response->header( 'Content-Type', 'application/activity+json' );
115-
116-
return $response;
115+
return $rest_response;
117116
}
118117

119118
/**
@@ -138,7 +137,10 @@ public static function user_inbox_post( $request ) {
138137
\do_action( 'activitypub_inbox', $data, $user->get__id(), $type );
139138
\do_action( "activitypub_inbox_{$type}", $data, $user->get__id() );
140139

141-
return new WP_REST_Response( array(), 202 );
140+
$rest_response = new WP_REST_Response( array(), 202 );
141+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
142+
143+
return $rest_response;
142144
}
143145

144146
/**
@@ -183,7 +185,10 @@ public static function shared_inbox_post( $request ) {
183185
\do_action( "activitypub_inbox_{$type}", $data, $user->ID );
184186
}
185187

186-
return new WP_REST_Response( array(), 202 );
188+
$rest_response = new WP_REST_Response( array(), 202 );
189+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
190+
191+
return $rest_response;
187192
}
188193

189194
/**

includes/rest/class-outbox.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ public static function user_outbox_get( $request ) {
123123
*/
124124
\do_action( 'activitypub_outbox_post' );
125125

126-
$response = new WP_REST_Response( $json, 200 );
126+
$rest_response = new WP_REST_Response( $json, 200 );
127+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
127128

128-
$response->header( 'Content-Type', 'application/activity+json' );
129-
130-
return $response;
129+
return $rest_response;
131130
}
132131

133132
/**

includes/rest/class-server.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ public static function application_actor() {
5454

5555
$json = $user->to_array();
5656

57-
$response = new WP_REST_Response( $json, 200 );
57+
$rest_response = new WP_REST_Response( $json, 200 );
58+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
5859

59-
$response->header( 'Content-Type', 'application/activity+json' );
60-
61-
return $response;
60+
return $rest_response;
6261
}
6362

6463
/**

includes/rest/class-users.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ public static function get( $request ) {
9595

9696
$json = $user->to_array();
9797

98-
$response = new WP_REST_Response( $json, 200 );
99-
$response->header( 'Content-Type', 'application/activity+json' );
98+
$rest_response = new WP_REST_Response( $json, 200 );
99+
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
100100

101-
return $response;
101+
return $rest_response;
102102
}
103103

104104

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
114114
* Improved: loading of shortcodes
115115
* Updated: caching of followers
116116
* Updated: Application-User is no longer "indexable"
117+
* Updated: more consistent usage of the `application/activity+json` Content-Type
117118

118119
= 1.0.7 =
119120

0 commit comments

Comments
 (0)