100, 'limit_response_size' => 1048576, 'redirection' => 3, 'user-agent' => "$user_agent; ActivityPub", 'headers' => array( 'Accept' => 'application/activity+json', 'Content-Type' => 'application/activity+json', 'Digest' => "SHA-256=$digest", 'Signature' => $signature, 'Date' => $date, ), 'body' => $body, ); $response = \wp_safe_remote_post( $url, $args ); $code = \wp_remote_retrieve_response_code( $response ); if ( 400 <= $code && 500 >= $code ) { $response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ) ); } \do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id ); return $response; } /** * Send a GET Request with the needed HTTP Headers * * @param string $url The URL endpoint * @param int $user_id The WordPress User-ID * * @return array|WP_Error The GET Response or an WP_ERROR */ public static function get( $url ) { $date = \gmdate( 'D, d M Y H:i:s T' ); $signature = Signature::generate_signature( -1, 'get', $url, $date ); $wp_version = \get_bloginfo( 'version' ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $args = array( 'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ), 'limit_response_size' => 1048576, 'redirection' => 3, 'user-agent' => "$user_agent; ActivityPub", 'headers' => array( 'Accept' => 'application/activity+json', 'Content-Type' => 'application/activity+json', 'Signature' => $signature, 'Date' => $date, ), ); $response = \wp_safe_remote_get( $url, $args ); $code = \wp_remote_retrieve_response_code( $response ); if ( 400 <= $code && 500 >= $code ) { $response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ) ); } \do_action( 'activitypub_safe_remote_get_response', $response, $url, $user_id ); return $response; } }