toolkit/modules/ServiceRequest.jsm
author Florin Strugariu <fstrugariu@mozilla.com>
Fri, 19 Apr 2019 08:51:28 +0000
changeset 470344 70ebde4e0b6df1014cf66e77478b98e6bfd347dc
parent 455626 6b56696d713a7f7858f16235e37baa8307e73b49
child 481426 e5be4c59b7f15f98fabb32a68fc64050ddb62bcb
permissions -rw-r--r--
Bug 1545722 remove raptor-tp6-8-404 jobs r=AlexandruIonescu Differential Revision: https://phabricator.services.mozilla.com/D28180

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/**
  * This module consolidates various code and data update requests, so flags
  * can be set, Telemetry collected, etc. in a central place.
  */

const {Log} = ChromeUtils.import("resource://gre/modules/Log.jsm");
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGlobalGetters(this, ["XMLHttpRequest"]);

var EXPORTED_SYMBOLS = [ "ServiceRequest" ];

const logger = Log.repository.getLogger("ServiceRequest");
logger.level = Log.Level.Debug;
logger.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));

/**
  * ServiceRequest is intended to be a drop-in replacement for current users
  * of XMLHttpRequest.
  *
  * @param {Object} options - Options for underlying XHR, e.g. { mozAnon: bool }
  */
class ServiceRequest extends XMLHttpRequest {
  constructor(options) {
    super(options);
  }
  /**
    * Opens an XMLHttpRequest, and sets the NSS "beConservative" flag.
    * Requests are always async.
    *
    * @param {String} method - HTTP method to use, e.g. "GET".
    * @param {String} url - URL to open.
    * @param {Object} options - Additional options (reserved for future use).
    */
  open(method, url, options) {
    super.open(method, url, true);

    // Disable cutting edge features, like TLS 1.3, where middleboxes might brick us
    if (super.channel instanceof Ci.nsIHttpChannelInternal) {
      super.channel.QueryInterface(Ci.nsIHttpChannelInternal).beConservative = true;
    }
  }
}