Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
92
gaia/shared/test/integration/server.js
Executable file
92
gaia/shared/test/integration/server.js
Executable file
|
|
@ -0,0 +1,92 @@
|
|||
'use strict';
|
||||
|
||||
function Server(root, port, child) {
|
||||
this.root = root;
|
||||
this.port = port;
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
Server.prototype = {
|
||||
/**
|
||||
* Formats given input with localhost and port.
|
||||
*
|
||||
* @param {String} path part of url.
|
||||
* @return {String} url of location.
|
||||
*/
|
||||
url: function(path) {
|
||||
return 'http://localhost:' + this.port + '/' + path;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends signal to stop child process and stop server.
|
||||
*/
|
||||
stop: function() {
|
||||
this.child.send({
|
||||
action: 'stop'
|
||||
});
|
||||
this.child.kill();
|
||||
},
|
||||
|
||||
/**
|
||||
* Cork the response body of the given url while allowing headers.
|
||||
* @param {String} url to cork
|
||||
*/
|
||||
cork: function(url) {
|
||||
this.child.send({
|
||||
action: 'cork',
|
||||
args: url
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Allow the body to be sent after calling `.cork`.
|
||||
* @param {String} url to uncork
|
||||
*/
|
||||
uncork: function(url) {
|
||||
this.child.send({
|
||||
action: 'uncork',
|
||||
args: url
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Protects a URL using HTTP authentication.
|
||||
* @param {String} url to protect
|
||||
*/
|
||||
protect: function(url) {
|
||||
this.child.send({
|
||||
action: 'protect',
|
||||
args: url
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops protecting a URL.
|
||||
* @param {String} url to protect
|
||||
*/
|
||||
unprotect: function(url) {
|
||||
this.child.send({
|
||||
action: 'unprotect',
|
||||
args: url
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Spawn the child process where the http server lives.
|
||||
*
|
||||
* @param {Function} callback [Error err, Server server].
|
||||
*/
|
||||
Server.create = function(root, callback) {
|
||||
var fork = require('child_process').fork;
|
||||
var child = fork(__dirname + '/server_child.js', [root]);
|
||||
|
||||
// wait for start message ['start', PORT_NUMBER].
|
||||
child.on('message', function(data) {
|
||||
if (Array.isArray(data) && data[0] === 'start') {
|
||||
callback(null, new Server(root, data[1], child));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Server;
|
||||
Loading…
Reference in a new issue