mozilla / self-repair-server

This project is now EOL, replaced by Normandy Recipe Server.
6 stars 11 forks source link

both geo and user satisfcation are NOT HAPPENING #242

Closed gregglind closed 8 years ago

gregglind commented 8 years ago

cors:

function cors1 (url, method, data) {
  return new Promise(function (resolve, reject) {
    var createCORSRequest = function(method, url) {
      var xhr = new XMLHttpRequest();
      if ("withCredentials" in xhr) {
        // Most browsers.
        xhr.open(method, url, true);
      } else if (typeof XDomainRequest != "undefined") {
        // IE8 & IE9
        xhr = new XDomainRequest();
        xhr.open(method, url);
      } else {
        // CORS not supported.
        xhr = null;
      }
      return xhr;
    };

    console.log("creating", method, url)
    var xhr = createCORSRequest(method, url);

    xhr.onload = function() {
      // Success code goes here.
      console.log("OK")
      resolve("OK")
    };

    xhr.onerror = function() {
      // Error code goes here.
      console.error("NOPE")
      reject("nope");
    };

    console.log("data:", data);
    // now break it...
    xhr.setRequestHeader("Content-Type", 'application/json');

    xhr.send(JSON.stringify(data));
  })
}

The setRequestHeader line breaks things. Removing it from request gives a 415 error instead.

gregglind commented 8 years ago

see https://gist.github.com/gregglind/f8a2a3f9664ad1b59cbc for alt cors impl.

Problem was: http/2