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