mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1837176
- Converting httpd.js to an ES module. r=necko-reviewers,webdriver-reviewers,valentin,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D181158
This commit is contained in:
parent
603927366c
commit
b63f2ba7f9
@ -52,7 +52,7 @@ reftest.jar:
|
||||
res/ReftestFissionParent.jsm (ReftestFissionParent.jsm)
|
||||
res/ReftestFissionChild.jsm (ReftestFissionChild.jsm)
|
||||
res/AsyncSpellCheckTestHelper.sys.mjs (../../../editor/AsyncSpellCheckTestHelper.sys.mjs)
|
||||
res/httpd.jsm (../../../netwerk/test/httpserver/httpd.js)
|
||||
res/httpd.sys.mjs (../../../netwerk/test/httpserver/httpd.sys.mjs)
|
||||
res/StructuredLog.sys.mjs (../../../testing/modules/StructuredLog.sys.mjs)
|
||||
res/PerTestCoverageUtils.sys.mjs (../../../tools/code-coverage/PerTestCoverageUtils.sys.mjs)
|
||||
res/input.css (../../../editor/reftests/xul/input.css)
|
||||
|
@ -44,7 +44,9 @@ const {
|
||||
|
||||
g,
|
||||
} = ChromeUtils.import("resource://reftest/globals.jsm");
|
||||
const { HttpServer } = ChromeUtils.import("resource://reftest/httpd.jsm");
|
||||
const { HttpServer } = ChromeUtils.importESModule(
|
||||
"resource://reftest/httpd.sys.mjs"
|
||||
);
|
||||
const { ReadTopManifest, CreateUrls } = ChromeUtils.import(
|
||||
"resource://reftest/manifest.jsm"
|
||||
);
|
||||
|
@ -10,41 +10,6 @@
|
||||
* httpd.js.
|
||||
*/
|
||||
|
||||
var EXPORTED_SYMBOLS = [
|
||||
"dumpn",
|
||||
"HTTP_400",
|
||||
"HTTP_401",
|
||||
"HTTP_402",
|
||||
"HTTP_403",
|
||||
"HTTP_404",
|
||||
"HTTP_405",
|
||||
"HTTP_406",
|
||||
"HTTP_407",
|
||||
"HTTP_408",
|
||||
"HTTP_409",
|
||||
"HTTP_410",
|
||||
"HTTP_411",
|
||||
"HTTP_412",
|
||||
"HTTP_413",
|
||||
"HTTP_414",
|
||||
"HTTP_415",
|
||||
"HTTP_417",
|
||||
"HTTP_500",
|
||||
"HTTP_501",
|
||||
"HTTP_502",
|
||||
"HTTP_503",
|
||||
"HTTP_504",
|
||||
"HTTP_505",
|
||||
"HttpError",
|
||||
"HttpServer",
|
||||
"LineData",
|
||||
"NodeServer",
|
||||
"nsHttpHeaders",
|
||||
"overrideBinaryStreamsForTests",
|
||||
"WriteThroughCopier",
|
||||
"setDebuggingStatus",
|
||||
];
|
||||
|
||||
const CC = Components.Constructor;
|
||||
|
||||
const PR_UINT32_MAX = Math.pow(2, 32) - 1;
|
||||
@ -63,14 +28,12 @@ var DEBUG_TIMESTAMP = false; // non-const so tweakable in server tests
|
||||
* @param {boolean} debugTimestamp
|
||||
* Enables timestamping of the debugging output.
|
||||
*/
|
||||
function setDebuggingStatus(debug, debugTimestamp) {
|
||||
export function setDebuggingStatus(debug, debugTimestamp) {
|
||||
DEBUG = debug;
|
||||
DEBUG_TIMESTAMP = debugTimestamp;
|
||||
}
|
||||
|
||||
const { AppConstants } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/AppConstants.sys.mjs"
|
||||
);
|
||||
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
|
||||
|
||||
/**
|
||||
* Asserts that the given condition holds. If it doesn't, the given message is
|
||||
@ -98,10 +61,11 @@ function NS_ASSERT(cond, msg) {
|
||||
}
|
||||
|
||||
/** Constructs an HTTP error object. */
|
||||
function HttpError(code, description) {
|
||||
export function HttpError(code, description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
HttpError.prototype = {
|
||||
toString() {
|
||||
return this.code + " " + this.description;
|
||||
@ -111,30 +75,30 @@ HttpError.prototype = {
|
||||
/**
|
||||
* Errors thrown to trigger specific HTTP server responses.
|
||||
*/
|
||||
var HTTP_400 = new HttpError(400, "Bad Request");
|
||||
var HTTP_401 = new HttpError(401, "Unauthorized");
|
||||
var HTTP_402 = new HttpError(402, "Payment Required");
|
||||
var HTTP_403 = new HttpError(403, "Forbidden");
|
||||
var HTTP_404 = new HttpError(404, "Not Found");
|
||||
var HTTP_405 = new HttpError(405, "Method Not Allowed");
|
||||
var HTTP_406 = new HttpError(406, "Not Acceptable");
|
||||
var HTTP_407 = new HttpError(407, "Proxy Authentication Required");
|
||||
var HTTP_408 = new HttpError(408, "Request Timeout");
|
||||
var HTTP_409 = new HttpError(409, "Conflict");
|
||||
var HTTP_410 = new HttpError(410, "Gone");
|
||||
var HTTP_411 = new HttpError(411, "Length Required");
|
||||
var HTTP_412 = new HttpError(412, "Precondition Failed");
|
||||
var HTTP_413 = new HttpError(413, "Request Entity Too Large");
|
||||
var HTTP_414 = new HttpError(414, "Request-URI Too Long");
|
||||
var HTTP_415 = new HttpError(415, "Unsupported Media Type");
|
||||
var HTTP_417 = new HttpError(417, "Expectation Failed");
|
||||
export var HTTP_400 = new HttpError(400, "Bad Request");
|
||||
|
||||
var HTTP_500 = new HttpError(500, "Internal Server Error");
|
||||
var HTTP_501 = new HttpError(501, "Not Implemented");
|
||||
var HTTP_502 = new HttpError(502, "Bad Gateway");
|
||||
var HTTP_503 = new HttpError(503, "Service Unavailable");
|
||||
var HTTP_504 = new HttpError(504, "Gateway Timeout");
|
||||
var HTTP_505 = new HttpError(505, "HTTP Version Not Supported");
|
||||
export var HTTP_401 = new HttpError(401, "Unauthorized");
|
||||
export var HTTP_402 = new HttpError(402, "Payment Required");
|
||||
export var HTTP_403 = new HttpError(403, "Forbidden");
|
||||
export var HTTP_404 = new HttpError(404, "Not Found");
|
||||
export var HTTP_405 = new HttpError(405, "Method Not Allowed");
|
||||
export var HTTP_406 = new HttpError(406, "Not Acceptable");
|
||||
export var HTTP_407 = new HttpError(407, "Proxy Authentication Required");
|
||||
export var HTTP_408 = new HttpError(408, "Request Timeout");
|
||||
export var HTTP_409 = new HttpError(409, "Conflict");
|
||||
export var HTTP_410 = new HttpError(410, "Gone");
|
||||
export var HTTP_411 = new HttpError(411, "Length Required");
|
||||
export var HTTP_412 = new HttpError(412, "Precondition Failed");
|
||||
export var HTTP_413 = new HttpError(413, "Request Entity Too Large");
|
||||
export var HTTP_414 = new HttpError(414, "Request-URI Too Long");
|
||||
export var HTTP_415 = new HttpError(415, "Unsupported Media Type");
|
||||
export var HTTP_417 = new HttpError(417, "Expectation Failed");
|
||||
export var HTTP_500 = new HttpError(500, "Internal Server Error");
|
||||
export var HTTP_501 = new HttpError(501, "Not Implemented");
|
||||
export var HTTP_502 = new HttpError(502, "Bad Gateway");
|
||||
export var HTTP_503 = new HttpError(503, "Service Unavailable");
|
||||
export var HTTP_504 = new HttpError(504, "Gateway Timeout");
|
||||
export var HTTP_505 = new HttpError(505, "HTTP Version Not Supported");
|
||||
|
||||
/** Creates a hash with fields corresponding to the values in arr. */
|
||||
function array2obj(arr) {
|
||||
@ -183,7 +147,7 @@ const SJS_TYPE = "sjs";
|
||||
var firstStamp = 0;
|
||||
|
||||
/** dump(str) with a trailing "\n" -- only outputs if DEBUG. */
|
||||
function dumpn(str) {
|
||||
export function dumpn(str) {
|
||||
if (DEBUG) {
|
||||
var prefix = "HTTPD-INFO | ";
|
||||
if (DEBUG_TIMESTAMP) {
|
||||
@ -270,7 +234,7 @@ var BinaryOutputStream = CC(
|
||||
"setOutputStream"
|
||||
);
|
||||
|
||||
function overrideBinaryStreamsForTests(
|
||||
export function overrideBinaryStreamsForTests(
|
||||
inputStream,
|
||||
outputStream,
|
||||
responseSegmentSize
|
||||
@ -371,28 +335,10 @@ function toDateString(date) {
|
||||
return rv.replace("%date1%", toDate1(date));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out a human-readable representation of the object o and its fields,
|
||||
* omitting those whose names begin with "_" if showMembers != true (to ignore
|
||||
* "private" properties exposed via getters/setters).
|
||||
*/
|
||||
function printObj(o, showMembers) {
|
||||
var s = "******************************\n";
|
||||
s += "o = {\n";
|
||||
for (var i in o) {
|
||||
if (typeof i != "string" || showMembers || (!!i.length && i[0] != "_")) {
|
||||
s += " " + i + ": " + o[i] + ",\n";
|
||||
}
|
||||
}
|
||||
s += " };\n";
|
||||
s += "******************************";
|
||||
dumpn(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new HTTP server.
|
||||
*/
|
||||
function nsHttpServer() {
|
||||
export function nsHttpServer() {
|
||||
/** The port on which this server listens. */
|
||||
this._port = undefined;
|
||||
|
||||
@ -429,6 +375,7 @@ function nsHttpServer() {
|
||||
*/
|
||||
this._connections = {};
|
||||
}
|
||||
|
||||
nsHttpServer.prototype = {
|
||||
// NSISERVERSOCKETLISTENER
|
||||
|
||||
@ -912,9 +859,9 @@ nsHttpServer.prototype = {
|
||||
},
|
||||
};
|
||||
|
||||
var HttpServer = nsHttpServer;
|
||||
export var HttpServer = nsHttpServer;
|
||||
|
||||
class NodeServer {
|
||||
export class NodeServer {
|
||||
// Executes command in the context of a node server.
|
||||
// See handler in moz-http2.js
|
||||
//
|
||||
@ -2084,7 +2031,7 @@ function findCRLF(array, start) {
|
||||
* A container which provides line-by-line access to the arrays of bytes with
|
||||
* which it is seeded.
|
||||
*/
|
||||
function LineData() {
|
||||
export function LineData() {
|
||||
/** An array of queued bytes from which to get line-based characters. */
|
||||
this._data = [];
|
||||
|
||||
@ -2928,7 +2875,7 @@ ServerHandler.prototype = {
|
||||
// If you update the list of imports, please update the list in
|
||||
// tools/lint/eslint/eslint-plugin-mozilla/lib/environments/sjs.js
|
||||
// as well.
|
||||
var s = Cu.Sandbox(globalThis);
|
||||
var s = Cu.Sandbox(Cu.getGlobalForObject({}));
|
||||
s.importFunction(dump, "dump");
|
||||
s.importFunction(atob, "atob");
|
||||
s.importFunction(btoa, "btoa");
|
||||
@ -4605,7 +4552,7 @@ function wouldBlock(e) {
|
||||
* @throws NS_ERROR_NULL_POINTER
|
||||
* if source, sink, or observer are null
|
||||
*/
|
||||
function WriteThroughCopier(source, sink, observer, context) {
|
||||
export function WriteThroughCopier(source, sink, observer, context) {
|
||||
if (!source || !sink || !observer) {
|
||||
throw Components.Exception("", Cr.NS_ERROR_NULL_POINTER);
|
||||
}
|
||||
@ -5285,7 +5232,7 @@ nsHttpVersion.HTTP_1_1 = new nsHttpVersion("1.1");
|
||||
* values returned by .enumerator may not be equal case-sensitively to the
|
||||
* values passed to setHeader when adding headers to this.
|
||||
*/
|
||||
function nsHttpHeaders() {
|
||||
export function nsHttpHeaders() {
|
||||
/**
|
||||
* A hash of headers, with header field names as the keys and header field
|
||||
* values as the values. Header field names are case-insensitive, but upon
|
||||
@ -5613,60 +5560,3 @@ Request.prototype = {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new HTTP server listening for loopback traffic on the given port,
|
||||
* starts it, and runs the server until the server processes a shutdown request,
|
||||
* spinning an event loop so that events posted by the server's socket are
|
||||
* processed.
|
||||
*
|
||||
* This method is primarily intended for use in running this script from within
|
||||
* xpcshell and running a functional HTTP server without having to deal with
|
||||
* non-essential details.
|
||||
*
|
||||
* Note that running multiple servers using variants of this method probably
|
||||
* doesn't work, simply due to how the internal event loop is spun and stopped.
|
||||
*
|
||||
* @note
|
||||
* This method only works with Mozilla 1.9 (i.e., Firefox 3 or trunk code);
|
||||
* you should use this server as a component in Mozilla 1.8.
|
||||
* @param port
|
||||
* the port on which the server will run, or -1 if there exists no preference
|
||||
* for a specific port; note that attempting to use some values for this
|
||||
* parameter (particularly those below 1024) may cause this method to throw or
|
||||
* may result in the server being prematurely shut down
|
||||
* @param basePath
|
||||
* a local directory from which requests will be served (i.e., if this is
|
||||
* "/home/jwalden/" then a request to /index.html will load
|
||||
* /home/jwalden/index.html); if this is omitted, only the default URLs in
|
||||
* this server implementation will be functional
|
||||
*/
|
||||
function server(port, basePath) {
|
||||
if (basePath) {
|
||||
var lp = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
||||
lp.initWithPath(basePath);
|
||||
}
|
||||
|
||||
// if you're running this, you probably want to see debugging info
|
||||
DEBUG = true;
|
||||
|
||||
var srv = new nsHttpServer();
|
||||
if (lp) {
|
||||
srv.registerDirectory("/", lp);
|
||||
}
|
||||
srv.registerContentType("sjs", SJS_TYPE);
|
||||
srv.identity.setPrimary("http", "localhost", port);
|
||||
srv.start(port);
|
||||
|
||||
var thread = Services.tm.currentThread;
|
||||
while (!srv.isStopped()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
||||
// get rid of any pending requests
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
|
||||
DEBUG = false;
|
||||
}
|
@ -13,9 +13,9 @@ XPIDL_MODULE = "test_necko"
|
||||
XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell.ini"]
|
||||
|
||||
EXTRA_COMPONENTS += [
|
||||
"httpd.js",
|
||||
"httpd.sys.mjs",
|
||||
]
|
||||
|
||||
TESTING_JS_MODULES += [
|
||||
"httpd.js",
|
||||
"httpd.sys.mjs",
|
||||
]
|
||||
|
@ -7,11 +7,14 @@
|
||||
const {
|
||||
dumpn,
|
||||
LineData,
|
||||
HttpServer,
|
||||
nsHttpHeaders,
|
||||
overrideBinaryStreamsForTests,
|
||||
HttpServer,
|
||||
WriteThroughCopier,
|
||||
} = ChromeUtils.import("resource://testing-common/httpd.js");
|
||||
overrideBinaryStreamsForTests,
|
||||
} = ChromeUtils.importESModule("resource://testing-common/httpd.sys.mjs");
|
||||
|
||||
// if these tests fail, we'll want the debug output
|
||||
var linDEBUG = true;
|
||||
|
||||
var { XPCOMUtils } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/XPCOMUtils.sys.mjs"
|
||||
@ -21,19 +24,11 @@ var { NetUtil } = ChromeUtils.importESModule(
|
||||
);
|
||||
|
||||
const CC = Components.Constructor;
|
||||
|
||||
const ScriptableInputStream = CC(
|
||||
"@mozilla.org/scriptableinputstream;1",
|
||||
"nsIScriptableInputStream",
|
||||
"init"
|
||||
);
|
||||
const FileInputStream = CC(
|
||||
"@mozilla.org/network/file-input-stream;1",
|
||||
"nsIFileInputStream",
|
||||
"init"
|
||||
);
|
||||
|
||||
/* These two are non-const only so a test can overwrite them. */
|
||||
var BinaryInputStream = CC(
|
||||
"@mozilla.org/binaryinputstream;1",
|
||||
"nsIBinaryInputStream",
|
||||
@ -44,6 +39,11 @@ var BinaryOutputStream = CC(
|
||||
"nsIBinaryOutputStream",
|
||||
"setOutputStream"
|
||||
);
|
||||
const ScriptableInputStream = CC(
|
||||
"@mozilla.org/scriptableinputstream;1",
|
||||
"nsIScriptableInputStream",
|
||||
"init"
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructs a new nsHttpServer instance. This function is intended to
|
||||
|
@ -214,7 +214,7 @@ ARCHIVE_FILES = {
|
||||
{
|
||||
"source": buildconfig.topobjdir,
|
||||
"base": "dist/bin/components",
|
||||
"patterns": ["httpd.js"],
|
||||
"patterns": ["httpd.sys.mjs"],
|
||||
"dest": "bin/components",
|
||||
},
|
||||
{
|
||||
|
@ -2,23 +2,18 @@
|
||||
* 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/. */
|
||||
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
Log: "chrome://remote/content/shared/Log.sys.mjs",
|
||||
HTTP_404: "chrome://remote/content/server/httpd.sys.mjs",
|
||||
HTTP_405: "chrome://remote/content/server/httpd.sys.mjs",
|
||||
HTTP_500: "chrome://remote/content/server/httpd.sys.mjs",
|
||||
Protocol: "chrome://remote/content/cdp/Protocol.sys.mjs",
|
||||
RemoteAgentError: "chrome://remote/content/cdp/Error.sys.mjs",
|
||||
TabManager: "chrome://remote/content/shared/TabManager.sys.mjs",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
HTTP_404: "chrome://remote/content/server/HTTPD.jsm",
|
||||
HTTP_405: "chrome://remote/content/server/HTTPD.jsm",
|
||||
HTTP_500: "chrome://remote/content/server/HTTPD.jsm",
|
||||
});
|
||||
|
||||
export class JSONHandler {
|
||||
constructor(cdp) {
|
||||
this.cdp = cdp;
|
||||
|
@ -9,14 +9,11 @@ const lazy = {};
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
CDP: "chrome://remote/content/cdp/CDP.sys.mjs",
|
||||
Deferred: "chrome://remote/content/shared/Sync.sys.mjs",
|
||||
HttpServer: "chrome://remote/content/server/httpd.sys.mjs",
|
||||
Log: "chrome://remote/content/shared/Log.sys.mjs",
|
||||
WebDriverBiDi: "chrome://remote/content/webdriver-bidi/WebDriverBiDi.sys.mjs",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
HttpServer: "chrome://remote/content/server/HTTPD.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "logger", () => lazy.Log.get());
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "activeProtocols", () => {
|
||||
|
@ -8,7 +8,7 @@ remote.jar:
|
||||
content/components/RemoteAgent.sys.mjs (components/RemoteAgent.sys.mjs)
|
||||
|
||||
# transport layer (http / websocket)
|
||||
content/server/HTTPD.jsm (../netwerk/test/httpserver/httpd.js)
|
||||
content/server/httpd.sys.mjs (../netwerk/test/httpserver/httpd.sys.mjs)
|
||||
content/server/WebSocketHandshake.sys.mjs (server/WebSocketHandshake.sys.mjs)
|
||||
content/server/WebSocketTransport.sys.mjs (server/WebSocketTransport.sys.mjs)
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
[
|
||||
{
|
||||
"filename": "host-utils-116.0a1.en-US.linux-x86_64.tar.gz",
|
||||
"size": 144623521,
|
||||
"size": 144142962,
|
||||
"algorithm": "sha512",
|
||||
"digest": "687eaef9a933dea7f127e9e51dbb664744d5605b7f4366e45b46561edcac399f82705ee6bab6be337a6d90d75d54b4d0808299b963d3b5018a871b916d830424",
|
||||
"digest": "b4b98e530deacca3611aa132e4d34a0f52e9719575cdb122af4c8e7568a681910a5661bc6bb1ed82e3c91507a0570fa1dd85527129b2865ef3d212e781b2d851",
|
||||
"unpack": true,
|
||||
"visibility": "public"
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ TEST_HARNESS_FILES.testing.mochitest += [
|
||||
"/build/valgrind/cross-architecture.sup",
|
||||
"/build/valgrind/i386-pc-linux-gnu.sup",
|
||||
"/build/valgrind/x86_64-pc-linux-gnu.sup",
|
||||
"/netwerk/test/httpserver/httpd.js",
|
||||
"/netwerk/test/httpserver/httpd.sys.mjs",
|
||||
"bisection.py",
|
||||
"browser-harness.xhtml",
|
||||
"browser-test.js",
|
||||
|
@ -17,20 +17,19 @@ let protocolHandler = Services.io
|
||||
.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
let httpdJSPath = PathUtils.toFileURI(_HTTPD_PATH);
|
||||
|
||||
protocolHandler.setSubstitution(
|
||||
"httpd-server",
|
||||
Services.io.newURI(httpdJSPath)
|
||||
);
|
||||
|
||||
const { HttpServer, dumpn, setDebuggingStatus } = ChromeUtils.import(
|
||||
"resource://httpd-server/httpd.js"
|
||||
const { HttpServer, dumpn, setDebuggingStatus } = ChromeUtils.importESModule(
|
||||
"resource://httpd-server/httpd.sys.mjs"
|
||||
);
|
||||
|
||||
protocolHandler.setSubstitution(
|
||||
"mochitest-server",
|
||||
Services.io.newFileURI(__LOCATION__.parent)
|
||||
);
|
||||
|
||||
/* import-globals-from mochitestListingsUtils.js */
|
||||
Services.scriptloader.loadSubScript(
|
||||
"resource://mochitest-server/mochitestListingsUtils.js",
|
||||
|
Loading…
Reference in New Issue
Block a user