Skip to content

Commit 3202f0f

Browse files
joshuaspenceepriestley
authored andcommitted
Post data to the Aphlict server in JSON encoded form.
Summary: Ref T4324. Currently, notifications data is `POST`ed to the Aphlict server in the `application/x-www-form-urlencoded` format. This works fine for simple data but is problematic for nested data. For example: ```lang=php array( 'data' => array( 'key' => '6021329908492455737', 'type' => 'PhabricatorNotificationAdHocFeedStory', ), 'subscribers' => array( 'PHID-USER-y7ofqm276ejs62yqghge', ), ); ``` Is encoded as `data%5Bkey%5D=6021329908492455737&data%5Btype%5D=PhabricatorNotificationAdHocFeedStory&subscribers%5B0%5D=PHID-USER-y7ofqm276ejs62yqghge`. This string is then (incorrectly) decoded by `querystring.parse` as: ```lang=javascript > querystring.parse('data%5Bkey%5D=6021329908492455737&data%5Btype%5D=PhabricatorNotificationAdHocFeedStory&subscribers%5B0%5D=PHID-USER-y7ofqm276ejs62yqghge'); { 'data[key]': '6021329908492455737', 'data[type]': 'PhabricatorNotificationAdHocFeedStory', 'subscribers[0]': 'PHID-USER-y7ofqm276ejs62yqghge' } ``` Test Plan: Sent test notifications from `/notification/status/` and verified that the notifications still worked. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4324 Differential Revision: https://secure.phabricator.com/D9386
1 parent 8033a69 commit 3202f0f

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/applications/notification/client/PhabricatorNotificationClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
final class PhabricatorNotificationClient {
44

5-
const EXPECT_VERSION = 3;
5+
const EXPECT_VERSION = 4;
66

77
public static function getServerStatus() {
88
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
@@ -28,7 +28,7 @@ public static function getServerStatus() {
2828
public static function postMessage(array $data) {
2929
$server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
3030

31-
id(new HTTPSFuture($server_uri, $data))
31+
id(new HTTPSFuture($server_uri, json_encode($data)))
3232
->setMethod('POST')
3333
->setTimeout(1)
3434
->resolvex();

support/aphlict/server/aphlict_server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ if (process.getuid() !== 0) {
6363
var net = require('net');
6464
var http = require('http');
6565
var url = require('url');
66-
var querystring = require('querystring');
6766

6867
process.on('uncaughtException', function (err) {
6968
debug.log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err);
@@ -121,7 +120,7 @@ var receive_server = http.createServer(function(request, response) {
121120
request.on('end', function () {
122121
++messages_in;
123122

124-
var data = querystring.parse(body);
123+
var data = JSON.parse(body);
125124
debug.log('notification: ' + JSON.stringify(data));
126125
broadcast(data);
127126
response.end();
@@ -140,7 +139,7 @@ var receive_server = http.createServer(function(request, response) {
140139
'messages.in': messages_in,
141140
'messages.out': messages_out,
142141
'log': config.log,
143-
'version': 3
142+
'version': 4
144143
};
145144

146145
response.write(JSON.stringify(status));

0 commit comments

Comments
 (0)