mirror of https://github.com/nodejs/node.git
lint
parent
115c4942db
commit
dce072a67e
66
src/http.js
66
src/http.js
|
@ -51,9 +51,9 @@ function decode (s) {
|
||||||
|
|
||||||
node.http.parseUri = function (str) {
|
node.http.parseUri = function (str) {
|
||||||
var o = node.http.parseUri.options,
|
var o = node.http.parseUri.options,
|
||||||
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
|
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
|
||||||
uri = {},
|
uri = {},
|
||||||
i = 14;
|
i = 14;
|
||||||
|
|
||||||
while (i--) uri[o.key[i]] = m[i] || "";
|
while (i--) uri[o.key[i]] = m[i] || "";
|
||||||
|
|
||||||
|
@ -152,12 +152,10 @@ node.http.ServerResponse = function (connection, responses) {
|
||||||
|
|
||||||
if (connection_expression.exec(field)) {
|
if (connection_expression.exec(field)) {
|
||||||
sent_connection_header = true;
|
sent_connection_header = true;
|
||||||
if (close_expression.exec(value))
|
if (close_expression.exec(value)) this.closeOnFinish = true;
|
||||||
this.closeOnFinish = true;
|
|
||||||
} else if (transfer_encoding_expression.exec(field)) {
|
} else if (transfer_encoding_expression.exec(field)) {
|
||||||
sent_transfer_encoding_header = true;
|
sent_transfer_encoding_header = true;
|
||||||
if (chunk_expression.exec(value))
|
if (chunk_expression.exec(value)) chunked_encoding = true;
|
||||||
chunked_encoding = true;
|
|
||||||
} else if (content_length_expression.exec(field)) {
|
} else if (content_length_expression.exec(field)) {
|
||||||
sent_content_length_header = true;
|
sent_content_length_header = true;
|
||||||
}
|
}
|
||||||
|
@ -214,8 +212,7 @@ node.http.ServerResponse = function (connection, responses) {
|
||||||
|
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
this.finish = function () {
|
this.finish = function () {
|
||||||
if (chunked_encoding)
|
if (chunked_encoding) send(output, "0\r\n\r\n"); // last chunk
|
||||||
send(output, "0\r\n\r\n"); // last chunk
|
|
||||||
|
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
|
|
||||||
|
@ -310,10 +307,11 @@ node.http.Server = function (RequestHandler, options) {
|
||||||
|
|
||||||
// is this really needed?
|
// is this really needed?
|
||||||
connection.onEOF = function () {
|
connection.onEOF = function () {
|
||||||
if (responses.length == 0)
|
if (responses.length == 0) {
|
||||||
connection.close();
|
connection.close();
|
||||||
else
|
} else {
|
||||||
responses[responses.length-1].closeOnFinish = true;
|
responses[responses.length-1].closeOnFinish = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,12 +344,10 @@ node.http.Client = function (port, host) {
|
||||||
|
|
||||||
if (connection_expression.exec(field)) {
|
if (connection_expression.exec(field)) {
|
||||||
sent_connection_header = true;
|
sent_connection_header = true;
|
||||||
if (close_expression.exec(value))
|
if (close_expression.exec(value)) this.closeOnFinish = true;
|
||||||
this.closeOnFinish = true;
|
|
||||||
} else if (transfer_encoding_expression.exec(field)) {
|
} else if (transfer_encoding_expression.exec(field)) {
|
||||||
sent_transfer_encoding_header = true;
|
sent_transfer_encoding_header = true;
|
||||||
if (chunk_expression.exec(value))
|
if (chunk_expression.exec(value)) chunked_encoding = true;
|
||||||
chunked_encoding = true;
|
|
||||||
} else if (content_length_expression.exec(field)) {
|
} else if (content_length_expression.exec(field)) {
|
||||||
sent_content_length_header = true;
|
sent_content_length_header = true;
|
||||||
}
|
}
|
||||||
|
@ -459,10 +455,11 @@ node.http.Client = function (port, host) {
|
||||||
|
|
||||||
this.onHeaderValue = function (data) {
|
this.onHeaderValue = function (data) {
|
||||||
var last_pair = headers[headers.length-1];
|
var last_pair = headers[headers.length-1];
|
||||||
if (last_pair.length == 1)
|
if (last_pair.length == 1) {
|
||||||
last_pair[1] = data;
|
last_pair[1] = data;
|
||||||
else
|
} else {
|
||||||
last_pair[1] += data;
|
last_pair[1] += data;
|
||||||
|
}
|
||||||
last_was_value = true;
|
last_was_value = true;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -477,19 +474,20 @@ node.http.Client = function (port, host) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onBody = function (chunk) {
|
this.onBody = function (chunk) {
|
||||||
if (res.onBody)
|
if (res.onBody) {
|
||||||
return res.onBody(chunk);
|
return res.onBody(chunk);
|
||||||
else
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onMessageComplete = function () {
|
this.onMessageComplete = function () {
|
||||||
connection.close();
|
connection.close();
|
||||||
|
if (res.onBodyComplete) {
|
||||||
if (res.onBodyComplete)
|
|
||||||
return res.onBodyComplete();
|
return res.onBodyComplete();
|
||||||
else
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -520,21 +518,21 @@ node.http.Client = function (port, host) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
node.http.cat = function(url, encoding, callback) {
|
node.http.cat = function (url, encoding, callback) {
|
||||||
var uri = node.http.parseUri(url)
|
var uri = node.http.parseUri(url);
|
||||||
var req = new node.http.Client(uri.port || 80, uri.host).get(uri.path || "/")
|
var req = new node.http.Client(uri.port || 80, uri.host).get(uri.path || "/");
|
||||||
req.finish(function(res) {
|
req.finish(function (res) {
|
||||||
var status = res.statusCode == 200 ? 0 : -1;
|
var status = res.statusCode == 200 ? 0 : -1;
|
||||||
res.setBodyEncoding(encoding)
|
res.setBodyEncoding(encoding);
|
||||||
var content = ""
|
var content = "";
|
||||||
res.onBody = function(chunk) {
|
res.onBody = function (chunk) {
|
||||||
content += chunk;
|
content += chunk;
|
||||||
}
|
};
|
||||||
res.onBodyComplete = function() {
|
res.onBodyComplete = function () {
|
||||||
callback(status, content);
|
callback(status, content);
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
})(); // anonymous namespace
|
})(); // anonymous namespace
|
||||||
|
|
||||||
|
|
40
src/node.js
40
src/node.js
|
@ -30,6 +30,7 @@ node.path = new function () {
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
var part = arguments[i].toString();
|
var part = arguments[i].toString();
|
||||||
|
|
||||||
|
/* Some logic to shorten paths */
|
||||||
if (part === ".") continue;
|
if (part === ".") continue;
|
||||||
while (/^\.\//.exec(part)) part = part.replace(/^\.\//, "");
|
while (/^\.\//.exec(part)) part = part.replace(/^\.\//, "");
|
||||||
|
|
||||||
|
@ -47,28 +48,23 @@ node.path = new function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.dirname = function (path) {
|
this.dirname = function (path) {
|
||||||
if (path.charAt(0) !== "/")
|
if (path.charAt(0) !== "/") path = "./" + path;
|
||||||
path = "./" + path;
|
|
||||||
var parts = path.split("/");
|
var parts = path.split("/");
|
||||||
return parts.slice(0, parts.length-1).join("/");
|
return parts.slice(0, parts.length-1).join("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.filename = function (path) {
|
this.filename = function (path) {
|
||||||
if (path.charAt(0) !== "/")
|
if (path.charAt(0) !== "/") path = "./" + path;
|
||||||
path = "./" + path;
|
|
||||||
var parts = path.split("/");
|
var parts = path.split("/");
|
||||||
return parts[parts.length-1];
|
return parts[parts.length-1];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
node.cat = function(url_or_path, encoding, callback) {
|
node.cat = function(location, encoding, callback) {
|
||||||
var uri = node.http.parseUri(url_or_path)
|
var url_re = new RegExp("^http:\/\/");
|
||||||
if (uri.protocol) {
|
var f = url_re.exec(location) ? node.http.cat : node.fs.cat;
|
||||||
node.http.cat(url_or_path, encoding, callback)
|
f(location, encoding, callback);
|
||||||
} else {
|
};
|
||||||
node.fs.cat(url_or_path, encoding, callback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Module
|
// Module
|
||||||
|
|
||||||
|
@ -76,9 +72,11 @@ node.Module = function (o) {
|
||||||
this.parent = o.parent;
|
this.parent = o.parent;
|
||||||
this.target = o.target || {};
|
this.target = o.target || {};
|
||||||
|
|
||||||
if (!o.path) throw "path argument required";
|
if (!o.path) throw "path argument required";
|
||||||
if (o.path.charAt(0) == "/")
|
|
||||||
throw "Absolute module paths are not yet supported in Node";
|
if (o.path.charAt(0) == "/") {
|
||||||
|
throw "Absolute module paths are not yet supported by Node";
|
||||||
|
}
|
||||||
|
|
||||||
if (o.path.match(/:\/\//)) {
|
if (o.path.match(/:\/\//)) {
|
||||||
this.filename = o.path;
|
this.filename = o.path;
|
||||||
|
@ -94,8 +92,9 @@ node.Module = function (o) {
|
||||||
|
|
||||||
node.Module.prototype.load = function (callback) {
|
node.Module.prototype.load = function (callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (self.loaded)
|
if (self.loaded) {
|
||||||
throw "Module '" + self.filename + "' is already loaded.";
|
throw "Module '" + self.filename + "' is already loaded.";
|
||||||
|
}
|
||||||
|
|
||||||
node.cat(self.filename, "utf8", function (status, content) {
|
node.cat(self.filename, "utf8", function (status, content) {
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
|
@ -171,20 +170,19 @@ node.Module.prototype.exitChildren = function (callback) {
|
||||||
node.Module.prototype.exit = function (callback) {
|
node.Module.prototype.exit = function (callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (self.exited)
|
if (self.exited) {
|
||||||
throw "Module '" + self.filename + "' is already exited.";
|
throw "Module '" + self.filename + "' is already exited.";
|
||||||
|
}
|
||||||
|
|
||||||
this.exitChildren(function () {
|
this.exitChildren(function () {
|
||||||
if (self.onExit) {
|
if (self.onExit) self.onExit();
|
||||||
self.onExit();
|
|
||||||
}
|
|
||||||
self.exited = true;
|
self.exited = true;
|
||||||
if (callback) callback()
|
if (callback) callback()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
// Load the root module. I.E. the command line argument.
|
// Load the root module--the command line argument.
|
||||||
root_module = new node.Module({
|
root_module = new node.Module({
|
||||||
path: node.path.filename(ARGV[1]),
|
path: node.path.filename(ARGV[1]),
|
||||||
base_directory: node.path.dirname(ARGV[1]),
|
base_directory: node.path.dirname(ARGV[1]),
|
||||||
|
|
Loading…
Reference in New Issue