From e123ad0333787e91d63589553e199e11e9c2a5c3 Mon Sep 17 00:00:00 2001
From: yflory <yann.flory@xwiki.com>
Date: Thu, 11 May 2017 16:31:14 +0200
Subject: [PATCH] Use a POST request to get the storage limits

---
 rpc.js | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/rpc.js b/rpc.js
index dd84b6b29..2e603d7fb 100644
--- a/rpc.js
+++ b/rpc.js
@@ -461,12 +461,23 @@ var isPrivilegedUser = function (publicKey, cb) {
 var limits = {};
 var updateLimits = function (publicKey, cb) {
     if (typeof cb !== "function") { cb = function () {}; }
-    var domain = config.domain;
+    var body = JSON.stringify({
+        domain: config.domain,
+        subdomain: config.subdomain
+    });
     var options = {
         host: 'accounts.cryptpad.fr',
-        path: '/api/getAuthorized?domain=' + encodeURIComponent(domain)
+        path: '/api/getauthorized',
+        method: 'POST',
+        headers: {
+            "Content-Type": "application/json",
+            "Content-Length": Buffer.byteLength(body)
+        }
     };
-    var callback = function (response) {
+    var req = Https.request(options, function (response) {
+        if (!('' + req.statusCode).match(/^2\d\d$/)) {
+            return void cb('SERVER ERROR ' + req.statusCode);
+        }
         var str = '';
 
         response.on('data', function (chunk) {
@@ -486,11 +497,14 @@ var updateLimits = function (publicKey, cb) {
                 cb(e);
             }
         });
-    };
-    Https.get(options, callback).on('error', function (e) {
+    });
+
+    req.on('error', function (e) {
         console.error(e);
         cb(e);
     });
+
+    req.end(body);
 };
 var getLimit = function (publicKey, cb) {
     return void cb(null, typeof limits[publicKey] === "number" ? limits[publicKey] : DEFAULT_LIMIT);