validate js
This commit is contained in:
parent
0640517a91
commit
4b9f26c51a
136
src/http.js
136
src/http.js
@ -1,42 +1,43 @@
|
||||
(function () {
|
||||
CRLF = "\r\n";
|
||||
node.http.STATUS_CODES = { 100 : 'Continue'
|
||||
, 101 : 'Switching Protocols'
|
||||
, 200 : 'OK'
|
||||
, 201 : 'Created'
|
||||
, 202 : 'Accepted'
|
||||
, 203 : 'Non-Authoritative Information'
|
||||
, 204 : 'No Content'
|
||||
, 205 : 'Reset Content'
|
||||
, 206 : 'Partial Content'
|
||||
, 300 : 'Multiple Choices'
|
||||
, 301 : 'Moved Permanently'
|
||||
, 302 : 'Moved Temporarily'
|
||||
, 303 : 'See Other'
|
||||
, 304 : 'Not Modified'
|
||||
, 305 : 'Use Proxy'
|
||||
, 400 : 'Bad Request'
|
||||
, 401 : 'Unauthorized'
|
||||
, 402 : 'Payment Required'
|
||||
, 403 : 'Forbidden'
|
||||
, 404 : 'Not Found'
|
||||
, 405 : 'Method Not Allowed'
|
||||
, 406 : 'Not Acceptable'
|
||||
, 407 : 'Proxy Authentication Required'
|
||||
, 408 : 'Request Time-out'
|
||||
, 409 : 'Conflict'
|
||||
, 410 : 'Gone'
|
||||
, 411 : 'Length Required'
|
||||
, 412 : 'Precondition Failed'
|
||||
, 413 : 'Request Entity Too Large'
|
||||
, 414 : 'Request-URI Too Large'
|
||||
, 415 : 'Unsupported Media Type'
|
||||
, 500 : 'Internal Server Error'
|
||||
, 501 : 'Not Implemented'
|
||||
, 502 : 'Bad Gateway'
|
||||
, 503 : 'Service Unavailable'
|
||||
, 504 : 'Gateway Time-out'
|
||||
, 505 : 'HTTP Version not supported'
|
||||
node.http.STATUS_CODES = {
|
||||
100 : 'Continue',
|
||||
101 : 'Switching Protocols',
|
||||
200 : 'OK',
|
||||
201 : 'Created',
|
||||
202 : 'Accepted',
|
||||
203 : 'Non-Authoritative Information',
|
||||
204 : 'No Content',
|
||||
205 : 'Reset Content',
|
||||
206 : 'Partial Content',
|
||||
300 : 'Multiple Choices',
|
||||
301 : 'Moved Permanently',
|
||||
302 : 'Moved Temporarily',
|
||||
303 : 'See Other',
|
||||
304 : 'Not Modified',
|
||||
305 : 'Use Proxy',
|
||||
400 : 'Bad Request',
|
||||
401 : 'Unauthorized',
|
||||
402 : 'Payment Required',
|
||||
403 : 'Forbidden',
|
||||
404 : 'Not Found',
|
||||
405 : 'Method Not Allowed',
|
||||
406 : 'Not Acceptable',
|
||||
407 : 'Proxy Authentication Required',
|
||||
408 : 'Request Time-out',
|
||||
409 : 'Conflict',
|
||||
410 : 'Gone',
|
||||
411 : 'Length Required',
|
||||
412 : 'Precondition Failed',
|
||||
413 : 'Request Entity Too Large',
|
||||
414 : 'Request-URI Too Large',
|
||||
415 : 'Unsupported Media Type',
|
||||
500 : 'Internal Server Error',
|
||||
501 : 'Not Implemented',
|
||||
502 : 'Bad Gateway',
|
||||
503 : 'Service Unavailable',
|
||||
504 : 'Gateway Time-out',
|
||||
505 : 'HTTP Version not supported'
|
||||
};
|
||||
|
||||
/*
|
||||
@ -67,29 +68,30 @@ node.http.parseUri = function (str) {
|
||||
});
|
||||
uri.toString = function () { return str; };
|
||||
|
||||
for (var i = o.key.length - 1; i >= 0; i--){
|
||||
for (i = o.key.length - 1; i >= 0; i--){
|
||||
if (uri[o.key[i]] == "") delete uri[o.key[i]];
|
||||
};
|
||||
}
|
||||
|
||||
return uri;
|
||||
};
|
||||
|
||||
node.http.parseUri.options = {
|
||||
strictMode: false,
|
||||
key: [ "source"
|
||||
, "protocol"
|
||||
, "authority"
|
||||
, "userInfo"
|
||||
, "user"
|
||||
, "password"
|
||||
, "host"
|
||||
, "port"
|
||||
, "relative"
|
||||
, "path"
|
||||
, "directory"
|
||||
, "file"
|
||||
, "query"
|
||||
, "anchor"
|
||||
key: [
|
||||
"source",
|
||||
"protocol",
|
||||
"authority",
|
||||
"userInfo",
|
||||
"user",
|
||||
"password",
|
||||
"host",
|
||||
"port",
|
||||
"relative",
|
||||
"path",
|
||||
"directory",
|
||||
"file",
|
||||
"query",
|
||||
"anchor"
|
||||
],
|
||||
q: {
|
||||
name: "params",
|
||||
@ -121,7 +123,7 @@ function send (output, data, encoding) {
|
||||
encoding = "raw";
|
||||
|
||||
output.push([data, encoding]);
|
||||
};
|
||||
}
|
||||
|
||||
/* This is a wrapper around the LowLevelServer interface. It provides
|
||||
* connection handling, overflow checking, and some data buffering.
|
||||
@ -232,7 +234,7 @@ function connectionListener (connection) {
|
||||
connection.addListener("message_complete", function () {
|
||||
req.emit("complete");
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
node.http.ServerResponse = function (connection) {
|
||||
var responses = connection.responses;
|
||||
@ -249,12 +251,7 @@ node.http.ServerResponse = function (connection) {
|
||||
var sent_content_length_header = false;
|
||||
|
||||
var reason = node.http.STATUS_CODES[statusCode] || "unknown";
|
||||
var header = "HTTP/1.1 "
|
||||
+ statusCode.toString()
|
||||
+ " "
|
||||
+ reason
|
||||
+ CRLF
|
||||
;
|
||||
var header = "HTTP/1.1 " + statusCode.toString() + " " + reason + CRLF;
|
||||
|
||||
for (var i = 0; i < headers.length; i++) {
|
||||
var field = headers[i][0];
|
||||
@ -283,10 +280,7 @@ node.http.ServerResponse = function (connection) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( sent_content_length_header == false
|
||||
&& sent_transfer_encoding_header == false
|
||||
)
|
||||
{
|
||||
if ( sent_content_length_header == false && sent_transfer_encoding_header == false ) {
|
||||
header += "Transfer-Encoding: chunked\r\n";
|
||||
chunked_encoding = true;
|
||||
}
|
||||
@ -315,11 +309,12 @@ node.http.ServerResponse = function (connection) {
|
||||
responses = [];
|
||||
return;
|
||||
}
|
||||
if (responses.length > 0 && responses[0] === this)
|
||||
if (responses.length > 0 && responses[0] === this) {
|
||||
while (output.length > 0) {
|
||||
var out = output.shift();
|
||||
connection.send(out[0], out[1]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.finished = false;
|
||||
@ -348,11 +343,7 @@ node.http.Client.prototype.flush = function (request) {
|
||||
return;
|
||||
}
|
||||
//node.debug("HTTP CLIENT flush. readyState = " + connection.readyState);
|
||||
while ( request === this.requests[0]
|
||||
&& request.output.length > 0
|
||||
&& this.readyState == "open"
|
||||
)
|
||||
{
|
||||
while ( request === this.requests[0] && request.output.length > 0 && this.readyState == "open" ) {
|
||||
var out = request.output.shift();
|
||||
this.send(out[0], out[1]);
|
||||
}
|
||||
@ -363,7 +354,7 @@ node.http.createClient = function (port, host) {
|
||||
|
||||
client.requests = [];
|
||||
|
||||
client.reconnect = function () { return client.connect(port, host) };
|
||||
client.reconnect = function () { return client.connect(port, host); };
|
||||
|
||||
client.addListener("connect", function () {
|
||||
//node.debug("HTTP CLIENT onConnect. readyState = " + client.readyState);
|
||||
@ -508,7 +499,6 @@ function createClientRequest (connection, method, uri, header_lines) {
|
||||
req.sendBody = function (chunk, encoding) {
|
||||
if (sent_content_length_header == false && chunked_encoding == false) {
|
||||
throw "Content-Length header (or Transfer-Encoding:chunked) not set";
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunked_encoding) {
|
||||
|
30
src/node.js
30
src/node.js
@ -60,8 +60,7 @@ node.path = new function () {
|
||||
} else if (i === arguments.length - 1) {
|
||||
part = part.replace(/^\/*/, "");
|
||||
} else {
|
||||
part = part.replace(/^\/*/, "")
|
||||
.replace(/\/*$/, "/");
|
||||
part = part.replace(/^\/*/, "").replace(/\/*$/, "/");
|
||||
}
|
||||
joined += part;
|
||||
}
|
||||
@ -129,18 +128,17 @@ node.Module.prototype.load = function (callback) {
|
||||
self.target.__include = function (path) { self.newChild(path, self.target); };
|
||||
|
||||
// create wrapper function
|
||||
var wrapper = "function (__filename) {\n"
|
||||
+ " var onLoad;\n"
|
||||
+ " var onExit;\n"
|
||||
+ " var exports = this;\n"
|
||||
+ " var require = this.__require;\n"
|
||||
+ " var include = this.__include;\n"
|
||||
+ content
|
||||
+ "\n"
|
||||
+ " this.__onLoad = onLoad;\n"
|
||||
+ " this.__onExit = onExit;\n"
|
||||
+ "};\n"
|
||||
;
|
||||
var wrapper = "function (__filename) {\n"+
|
||||
" var onLoad;\n"+
|
||||
" var onExit;\n"+
|
||||
" var exports = this;\n"+
|
||||
" var require = this.__require;\n"+
|
||||
" var include = this.__include;\n"+
|
||||
content+
|
||||
"\n"+
|
||||
" this.__onLoad = onLoad;\n"+
|
||||
" this.__onExit = onExit;\n"+
|
||||
"};\n";
|
||||
var compiled_wrapper = node.compile(wrapper, self.filename);
|
||||
compiled_wrapper.apply(self.target, [self.filename]);
|
||||
self.onLoad = self.target.__onLoad;
|
||||
@ -200,7 +198,7 @@ node.Module.prototype.exit = function (callback) {
|
||||
this.exitChildren(function () {
|
||||
if (self.onExit) self.onExit();
|
||||
self.exited = true;
|
||||
if (callback) callback()
|
||||
if (callback) callback();
|
||||
});
|
||||
};
|
||||
|
||||
@ -218,4 +216,4 @@ node.Module.prototype.exit = function (callback) {
|
||||
node.reallyExit(code);
|
||||
});
|
||||
};
|
||||
}())
|
||||
}());
|
||||
|
@ -10,10 +10,10 @@ function onLoad () {
|
||||
var x = node.path.join(fixtures, "x.txt");
|
||||
|
||||
file = new node.fs.File;
|
||||
file.addListener("error", function () { got_error = true });
|
||||
file.addListener("error", function () { got_error = true; });
|
||||
|
||||
file.open(x, "r").addCallback(function () {
|
||||
opened = true
|
||||
opened = true;
|
||||
file.close().addCallback(function () {
|
||||
closed = true;
|
||||
});
|
||||
|
@ -16,16 +16,14 @@ var got_good_server_content = false;
|
||||
var bad_server_got_error = false;
|
||||
|
||||
function onLoad () {
|
||||
node.http.cat("http://localhost:"+PORT+"/", "utf8")
|
||||
.addCallback(function (content) {
|
||||
node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) {
|
||||
puts("got response");
|
||||
got_good_server_content = true;
|
||||
assertEquals(body, content);
|
||||
server.close();
|
||||
});
|
||||
|
||||
node.http.cat("http://localhost:12312/", "utf8")
|
||||
.addErrback(function () {
|
||||
node.http.cat("http://localhost:12312/", "utf8").addErrback(function () {
|
||||
puts("got error (this should happen)");
|
||||
bad_server_got_error = true;
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ function onLoad () {
|
||||
|
||||
promise.addCallback(function (content) {
|
||||
assertEquals(body, content);
|
||||
server.close()
|
||||
server.close();
|
||||
successes += 1;
|
||||
});
|
||||
|
||||
@ -35,7 +35,7 @@ function onLoad () {
|
||||
promise = node.cat(x, "utf8");
|
||||
|
||||
promise.addCallback(function (content) {
|
||||
assertEquals("xyz", content.replace(/[\r\n]/, ''))
|
||||
assertEquals("xyz", content.replace(/[\r\n]/, ''));
|
||||
successes += 1;
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user