Bug 1608150 [wpt PR 21112] - Add missing space in `./wpt lint` command line docs...
[gecko.git] / toolkit / modules / ServiceRequest.jsm
blobfdc1175e5aca1b54686ff5546092b9c94dc780e4
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 /**
8  * This module consolidates various code and data update requests, so flags
9  * can be set, Telemetry collected, etc. in a central place.
10  */
12 const { Log } = ChromeUtils.import("resource://gre/modules/Log.jsm");
13 const { XPCOMUtils } = ChromeUtils.import(
14   "resource://gre/modules/XPCOMUtils.jsm"
16 XPCOMUtils.defineLazyGlobalGetters(this, ["XMLHttpRequest"]);
18 var EXPORTED_SYMBOLS = ["ServiceRequest"];
20 const logger = Log.repository.getLogger("ServiceRequest");
21 logger.level = Log.Level.Debug;
22 logger.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
24 /**
25  * ServiceRequest is intended to be a drop-in replacement for current users
26  * of XMLHttpRequest.
27  *
28  * @param {Object} options - Options for underlying XHR, e.g. { mozAnon: bool }
29  */
30 class ServiceRequest extends XMLHttpRequest {
31   constructor(options) {
32     super(options);
33   }
34   /**
35    * Opens an XMLHttpRequest, and sets the NSS "beConservative" flag.
36    * Requests are always async.
37    *
38    * @param {String} method - HTTP method to use, e.g. "GET".
39    * @param {String} url - URL to open.
40    * @param {Object} options - Additional options (reserved for future use).
41    */
42   open(method, url, options) {
43     super.open(method, url, true);
45     // Disable cutting edge features, like TLS 1.3, where middleboxes might brick us
46     if (super.channel instanceof Ci.nsIHttpChannelInternal) {
47       super.channel.QueryInterface(
48         Ci.nsIHttpChannelInternal
49       ).beConservative = true;
50     }
51   }