mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-29 12:01:43 +00:00
Update httpserver.js
This commit is contained in:
parent
c38f6a8858
commit
a62837ed25
|
|
@ -2,39 +2,73 @@
|
||||||
// HTTPServer API
|
// HTTPServer API
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var SHELL = require("lib/shell");
|
var HTTPServer = {
|
||||||
|
_this: this, // Avoid conflicts between HTTPServer and Winsock variables
|
||||||
|
|
||||||
var ResponseCodes = {
|
StatusCodes: {
|
||||||
100: "Continue",
|
100: "Continue",
|
||||||
200: "OK",
|
200: "OK",
|
||||||
206: "Partial Content",
|
206: "Partial Content",
|
||||||
301: "Moved Permanently",
|
301: "Moved Permanently",
|
||||||
302: "Found",
|
302: "Found",
|
||||||
304: "Not Modified",
|
304: "Not Modified",
|
||||||
400: "Bad Request",
|
400: "Bad Request",
|
||||||
401: "Unauthorized",
|
401: "Unauthorized",
|
||||||
403: "Forbidden",
|
403: "Forbidden",
|
||||||
404: "Not Found",
|
404: "Not Found",
|
||||||
500: "Internal Server Error",
|
500: "Internal Server Error",
|
||||||
503: "Service Unavailable"
|
503: "Service Unavailable"
|
||||||
};
|
},
|
||||||
|
|
||||||
var listener, http = {};
|
Listener: null,
|
||||||
|
|
||||||
var listen = function(port) {
|
Connections: {},
|
||||||
try {
|
|
||||||
listener = CreateObject("MSWinsock.Winsock.1", "listener_");
|
Bind: function(port) {
|
||||||
listener.localPort = port;
|
try {
|
||||||
listener.bind();
|
_this.Listener = CreateObject(["MSWinsock.Winsock.1", "MSWinsock.Winsock"], "listener_");
|
||||||
listener.listen();
|
_this.Listener.localPort = port;
|
||||||
console.info("Listening port: " + port);
|
_this.Listener.bind();
|
||||||
} catch(e) {
|
_this.Listener.listen();
|
||||||
console.error("port " + port " could not bind: " + e.message);
|
console.info("Listening port: " + port);
|
||||||
|
} catch(e) {
|
||||||
|
console.error("port " + port " could not bind: " + e.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
OnRequest : function(request, response) {
|
||||||
|
console.log("HTTPServer.OnRequest() dose not implemented");
|
||||||
|
},
|
||||||
|
|
||||||
|
CreateServer: function(OnRequest) {
|
||||||
|
if(typeof OnRequest !== "function") {
|
||||||
|
throw new TypeError("OnRequest() must be a function.");
|
||||||
|
}
|
||||||
|
_this.OnRequest = OnRequest;
|
||||||
|
|
||||||
|
return HTTPServer;
|
||||||
|
},
|
||||||
|
|
||||||
|
ConnectionRequest: function(requestID) {
|
||||||
|
console.info("Connection request " + requestID);
|
||||||
|
|
||||||
|
_this.Connections[requestID] = {
|
||||||
|
Listener: CreateObject(["MSWinsock.Winsock.1", "MSWinsock.Winsock"], "listener_");
|
||||||
|
};
|
||||||
|
_this.Connections[requestID].Listener.accept(requestID);
|
||||||
|
},
|
||||||
|
|
||||||
|
DataArrival: function(length) {
|
||||||
|
// TODO: DataArrival
|
||||||
|
},
|
||||||
|
|
||||||
|
SendComplete: function() {
|
||||||
|
// TODO: SendComplete
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var arrival = function() {
|
global.listener_ConnectionRequest = HTTPServer.ConnectionRequest;
|
||||||
// todo
|
global.listener_DataArrival = HTTPServer.DataArrival;
|
||||||
};
|
global.listener_SendComplete = HTTPServer.SendComplete;
|
||||||
|
|
||||||
// todo
|
exports = HTTPServer;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user