Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/299203
Change subject: Add Http::sendBeacon() ...................................................................... Add Http::sendBeacon() Add a PHP implementation of `navigator.sendBeacon`, part of the JavaScript Beacon web API. Http::sendBeacon() matches it in signature and behavior, sending a POST request to the specified URL with the specified payload and doing so asyncronously, after processing the request. The intended use-case is for sending a pingback to mediawiki.org post-install (with the user's consent). That will be implemented in a follow-up commit. Change-Id: I4de23b1154056b6578aeb79fc5460462135deb91 --- M includes/HttpFunctions.php 1 file changed, 23 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/03/299203/1 diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index b12f49f..3509384 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -212,6 +212,29 @@ return ""; } + + /** + * Asynchronously transfer small HTTP data from the User Agent to a web server. + * + * This method closely matches navigator.sendBeacon(), which is part of the + * Beacon web API. See <https://w3c.github.io/beacon/#sec-sendBeacon-method> + * and <https://developer.mozilla.org/en/docs/Web/API/Navigator/sendBeacon>. + * + * If you need to pass advanced options to Http::post, call it directly. + * + * @param string $url the URL where the data is to be transmitted. + * @param mixed $data (optional) data to be transmitted as an array of + * key-value pairs or as URL-encoded form data. + * @return true + */ + public static function sendBeacon( $url, array $data = [] ) { + $options = $data ? [ 'postData' => $data ] : []; + DeferredUpdates::addCallableUpdate( function () use ( $url, $options ) { + Http::post( $url, $options ); + } ); + + return true; + } } /** -- To view, visit https://gerrit.wikimedia.org/r/299203 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4de23b1154056b6578aeb79fc5460462135deb91 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits