Merge remote-tracking branch 'ry/v0.10'

Conflicts:
	lib/tls.js
This commit is contained in:
isaacs 2013-08-21 09:40:10 -07:00
commit cdf2a661f2
8 changed files with 98 additions and 29 deletions

View File

@ -936,6 +936,7 @@ size_t http_parser_execute (http_parser *parser,
} else if (parser->index == 2 && ch == 'P') { } else if (parser->index == 2 && ch == 'P') {
parser->method = HTTP_COPY; parser->method = HTTP_COPY;
} else { } else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
} else if (parser->method == HTTP_MKCOL) { } else if (parser->method == HTTP_MKCOL) {
@ -948,12 +949,14 @@ size_t http_parser_execute (http_parser *parser,
} else if (parser->index == 2 && ch == 'A') { } else if (parser->index == 2 && ch == 'A') {
parser->method = HTTP_MKACTIVITY; parser->method = HTTP_MKACTIVITY;
} else { } else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
} else if (parser->method == HTTP_SUBSCRIBE) { } else if (parser->method == HTTP_SUBSCRIBE) {
if (parser->index == 1 && ch == 'E') { if (parser->index == 1 && ch == 'E') {
parser->method = HTTP_SEARCH; parser->method = HTTP_SEARCH;
} else { } else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
} else if (parser->index == 1 && parser->method == HTTP_POST) { } else if (parser->index == 1 && parser->method == HTTP_POST) {
@ -964,13 +967,27 @@ size_t http_parser_execute (http_parser *parser,
} else if (ch == 'A') { } else if (ch == 'A') {
parser->method = HTTP_PATCH; parser->method = HTTP_PATCH;
} else { } else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
} else if (parser->index == 2) { } else if (parser->index == 2) {
if (parser->method == HTTP_PUT) { if (parser->method == HTTP_PUT) {
if (ch == 'R') parser->method = HTTP_PURGE; if (ch == 'R') {
parser->method = HTTP_PURGE;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->method == HTTP_UNLOCK) { } else if (parser->method == HTTP_UNLOCK) {
if (ch == 'S') parser->method = HTTP_UNSUBSCRIBE; if (ch == 'S') {
parser->method = HTTP_UNSUBSCRIBE;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
} }
} else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
parser->method = HTTP_PROPPATCH; parser->method = HTTP_PROPPATCH;

View File

@ -3117,14 +3117,8 @@ main (void)
/// REQUESTS /// REQUESTS
test_simple("hello world", HPE_INVALID_METHOD);
test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION); test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
test_simple("ASDF / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
test_simple("GETA / HTTP/1.1\r\n\r\n", HPE_INVALID_METHOD);
// Well-formed but incomplete // Well-formed but incomplete
test_simple("GET / HTTP/1.1\r\n" test_simple("GET / HTTP/1.1\r\n"
"Content-Type: text/plain\r\n" "Content-Type: text/plain\r\n"
@ -3167,13 +3161,23 @@ main (void)
} }
static const char *bad_methods[] = { static const char *bad_methods[] = {
"ASDF",
"C******", "C******",
"COLA",
"GEM",
"GETA",
"M****", "M****",
"MKCOLA",
"PROPPATCHA",
"PUN",
"PX",
"SA",
"hello world",
0 }; 0 };
for (this_method = bad_methods; *this_method; this_method++) { for (this_method = bad_methods; *this_method; this_method++) {
char buf[200]; char buf[200];
sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method); sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
test_simple(buf, HPE_UNKNOWN); test_simple(buf, HPE_INVALID_METHOD);
} }
const char *dumbfuck2 = const char *dumbfuck2 =

View File

@ -132,13 +132,21 @@ informing the source that the data did not reach its intended recipient).
* `port` Integer * `port` Integer
* `address` String, Optional * `address` String, Optional
* `callback` Function, Optional * `callback` Function with no parameters, Optional. Callback when
binding is done.
For UDP sockets, listen for datagrams on a named `port` and optional `address`. For UDP sockets, listen for datagrams on a named `port` and optional
If `address` is not specified, the OS will try to listen on all addresses. `address`. If `address` is not specified, the OS will try to listen on
all addresses. After binding is done, a "listening" event is emitted
and the `callback`(if specified) is called. Specifying both a
"listening" event listener and `callback` is not harmful but not very
useful.
The `callback` argument, if provided, is added as a one-shot `'listening'` A bound datagram socket keeps the node process running to receive
event listener. datagrams.
If binding fails, an "error" event is generated. In rare case (e.g.
binding a closed socket), an `Error` may be thrown by this method.
Example of a UDP server listening on port 41234: Example of a UDP server listening on port 41234:
@ -146,6 +154,11 @@ Example of a UDP server listening on port 41234:
var server = dgram.createSocket("udp4"); var server = dgram.createSocket("udp4");
server.on("error", function (err) {
console.log("server error:\n" + err.stack);
server.close();
});
server.on("message", function (msg, rinfo) { server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + console.log("server got: " + msg + " from " +
rinfo.address + ":" + rinfo.port); rinfo.address + ":" + rinfo.port);

View File

@ -167,6 +167,28 @@ Example:
/usr/local/bin/node /usr/local/bin/node
## process.execArgv
This is the set of node-specific command line options from the
executable that started the process. These options do not show up in
`process.argv`, and do not include the node executable, the name of
the script, or any options following the script name. These options
are useful in order to spawn child processes with the same execution
environment as the parent.
Example:
$ node --harmony script.js --version
results in process.execArgv:
['--harmony']
and process.argv:
['/usr/local/bin/node', 'script.js', '--version']
## process.abort() ## process.abort()
This causes node to emit an abort. This will cause node to exit and This causes node to emit an abort. This will cause node to exit and

View File

@ -1085,8 +1085,8 @@ connected in some way to the input, such as a [zlib][] stream or a
There is no requirement that the output be the same size as the input, There is no requirement that the output be the same size as the input,
the same number of chunks, or arrive at the same time. For example, a the same number of chunks, or arrive at the same time. For example, a
Hash stream will only ever have a single chunk of output which is Hash stream will only ever have a single chunk of output which is
provided when the input is ended. A zlib stream will either produce provided when the input is ended. A zlib stream will produce output
much smaller or much larger than its input. that is either much smaller or much larger than its input.
Rather than implement the [`_read()`][] and [`_write()`][] methods, Transform Rather than implement the [`_read()`][] and [`_write()`][] methods, Transform
classes must implement the `_transform()` method, and may optionally classes must implement the `_transform()` method, and may optionally
@ -1174,7 +1174,7 @@ approach.
```javascript ```javascript
var util = require('util'); var util = require('util');
var Transform = require('stream').Transform); var Transform = require('stream').Transform;
util.inherits(SimpleProtocol, Transform); util.inherits(SimpleProtocol, Transform);
function SimpleProtocol(options) { function SimpleProtocol(options) {

View File

@ -268,7 +268,14 @@ CryptoStream.prototype._read = function read(size) {
// Get NPN and Server name when ready // Get NPN and Server name when ready
this.pair.maybeInitFinished(); this.pair.maybeInitFinished();
} while (read > 0 && !this._buffer.isFull && bytesRead < size);
// `maybeInitFinished()` can emit the 'secure' event which
// in turn destroys the connection in case of authentication
// failure and sets `this.pair.ssl` to `null`.
} while (read > 0 &&
!this._buffer.isFull &&
bytesRead < size &&
this.pair.ssl !== null);
// Create new buffer if previous was filled up // Create new buffer if previous was filled up
var pool = this._buffer.pool; var pool = this._buffer.pool;

View File

@ -1465,7 +1465,7 @@ ReadStream.prototype.open = function() {
var self = this; var self = this;
fs.open(this.path, this.flags, this.mode, function(er, fd) { fs.open(this.path, this.flags, this.mode, function(er, fd) {
if (er) { if (er) {
if (this.autoClose) { if (self.autoClose) {
self.destroy(); self.destroy();
} }
self.emit('error', er); self.emit('error', er);

View File

@ -171,10 +171,6 @@ function file7Next(){
}); });
file7.on('end', function(err) { file7.on('end', function(err) {
assert.equal(file7.data, 'xyz\n'); assert.equal(file7.data, 'xyz\n');
process.nextTick(function() {
assert(file7.closed);
assert(file7.destroyed);
});
}); });
} }
@ -182,10 +178,20 @@ function file7Next(){
var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
file8.on('data', function() {}); file8.on('data', function() {});
file8.on('error', common.mustCall(function() {})); file8.on('error', common.mustCall(function() {}));
file8.on('end', function() {
process.nextTick(function() { // Make sure stream is destroyed when file does not exist.
var file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
file9.on('data', function() {});
file9.on('error', common.mustCall(function() {}));
process.on('exit', function() {
assert(file7.closed);
assert(file7.destroyed);
assert(!file8.closed); assert(!file8.closed);
assert(!file8.destroyed); assert(!file8.destroyed);
assert(file8.fd); assert(file8.fd);
});
assert(!file9.closed);
assert(file9.destroyed);
}); });