Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
use json instead of x-wblahhh for xhr requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Apr 12, 2017
1 parent bd9ee22 commit af20b24
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions addon/webextension/background/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ this.auth = (function () {
// TODO: replace xhr with Fetch #2261
let req = new XMLHttpRequest();
req.open("POST", registerUrl);
req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("content-type", "application/json");
req.onload = catcher.watchFunction(() => {
if (req.status == 200) {
console.info("Registered login");
Expand All @@ -66,7 +66,7 @@ this.auth = (function () {
exc.popupMessage = "LOGIN_CONNECTION_ERROR";
reject(exc);
});
req.send(uriEncode({
req.send(JSON.stringify({
deviceId: registrationInfo.deviceId,
secret: registrationInfo.secret,
deviceInfo: JSON.stringify(deviceInfo())
Expand Down Expand Up @@ -119,8 +119,8 @@ this.auth = (function () {
exc.popupMessage = "CONNECTION_ERROR";
reject(exc);
});
req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
req.send(uriEncode({
req.setRequestHeader("content-type", "application/json");
req.send(JSON.stringify({
deviceId: registrationInfo.deviceId,
secret: registrationInfo.secret,
deviceInfo: JSON.stringify(deviceInfo()),
Expand All @@ -146,16 +146,6 @@ this.auth = (function () {
}
}

function uriEncode(obj) {
let s = [];
for (let key in obj) {
if (obj[key] !== undefined) {
s.push(`${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`);
}
}
return s.join("&");
}

exports.getDeviceId = function () {
return registrationInfo.deviceId;
};
Expand Down

0 comments on commit af20b24

Please sign in to comment.