Skip to content

Commit

Permalink
Improve the URL redirects endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons committed Jan 23, 2020
1 parent b3d6e74 commit 1691393
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ public function register_routes() {
* @return WP_REST_Response The REST API response.
*/
public function follow_redirect( $request ) {
global $wp_version;

// Add a User-Agent header since the request is sometimes blocked without it.
$response = wp_safe_remote_get(
$request['url'],
array(
'headers' => array(
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0',
// @see https://github.com/Automattic/jetpack/blob/fe51754410f97e0f20908ebb7fdbfbc62e703987/modules/protect.php#L534
'User-Agent' => "WordPress/{$wp_version} | Jetpack/" . constant( 'JETPACK__VERSION' ),
),
)
);
Expand All @@ -70,7 +73,7 @@ public function follow_redirect( $request ) {
return rest_ensure_response(
array(
'url' => '',
'status' => null,
'status' => $response->get_error_code(),
)
);
}
Expand Down

0 comments on commit 1691393

Please sign in to comment.