Skip to content

Commit

Permalink
Manually construct query strings for browser-request instances
Browse files Browse the repository at this point in the history
Because `request` just doesn't work for us in the browser, but `browser-request` is fine despite us having to do our own query strings.

Fixes element-hq/element-web#7620
  • Loading branch information
turt2live committed Oct 30, 2018
1 parent 11968a5 commit f288112
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion browser-index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var matrixcs = require("./lib/matrix");
matrixcs.request(require("request"));
var request = require("browser-request");
request.enableConstructionOfQueryString = true; // note: this is long so we hopefully don't collide
matrixcs.request(request);

// just *accessing* indexedDB throws an exception in firefox with
// indexeddb disabled.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"content-type": "^1.0.2",
"loglevel": "1.6.1",
"memfs": "^2.10.1",
"query-string": "^6.2.0",
"request": "^2.88.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
* @module http-api
*/
import Promise from 'bluebird';
const queryString = require('query-string');
const parseContentType = require('content-type').parse;

const utils = require("./utils");
Expand Down Expand Up @@ -746,6 +747,9 @@ module.exports.MatrixHttpApi.prototype = {
const reqPromise = defer.promise;

try {
if (this.opts.request.enableConstructionOfQueryString) {
queryParams = queryString.stringify(queryParams, opts.qsStringifyOptions);
}
req = this.opts.request(
{
uri: uri,
Expand Down

0 comments on commit f288112

Please sign in to comment.