1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

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
This commit is contained in:
Joshua Spence 2014-06-05 09:47:33 -07:00 committed by epriestley
parent 8033a69746
commit 3202f0f23d
2 changed files with 4 additions and 5 deletions

View file

@ -2,7 +2,7 @@
final class PhabricatorNotificationClient { final class PhabricatorNotificationClient {
const EXPECT_VERSION = 3; const EXPECT_VERSION = 4;
public static function getServerStatus() { public static function getServerStatus() {
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); $uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
@ -28,7 +28,7 @@ final class PhabricatorNotificationClient {
public static function postMessage(array $data) { public static function postMessage(array $data) {
$server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri'); $server_uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
id(new HTTPSFuture($server_uri, $data)) id(new HTTPSFuture($server_uri, json_encode($data)))
->setMethod('POST') ->setMethod('POST')
->setTimeout(1) ->setTimeout(1)
->resolvex(); ->resolvex();

View file

@ -63,7 +63,6 @@ if (process.getuid() !== 0) {
var net = require('net'); var net = require('net');
var http = require('http'); var http = require('http');
var url = require('url'); var url = require('url');
var querystring = require('querystring');
process.on('uncaughtException', function (err) { process.on('uncaughtException', function (err) {
debug.log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err); debug.log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err);
@ -121,7 +120,7 @@ var receive_server = http.createServer(function(request, response) {
request.on('end', function () { request.on('end', function () {
++messages_in; ++messages_in;
var data = querystring.parse(body); var data = JSON.parse(body);
debug.log('notification: ' + JSON.stringify(data)); debug.log('notification: ' + JSON.stringify(data));
broadcast(data); broadcast(data);
response.end(); response.end();
@ -140,7 +139,7 @@ var receive_server = http.createServer(function(request, response) {
'messages.in': messages_in, 'messages.in': messages_in,
'messages.out': messages_out, 'messages.out': messages_out,
'log': config.log, 'log': config.log,
'version': 3 'version': 4
}; };
response.write(JSON.stringify(status)); response.write(JSON.stringify(status));