For classes defined in the module, this is fine. For 'Error'
it's probably not very hazardous. However, testing 'Object'
and 'String' is much more reliable using typeof, to work with
the repl and NODE_MODULE_CONTEXT modes.
The file:// protocol *always* has a hostname; it's frequently
abbreviated as an empty string, which represents 'localhost'
implicitly.
According to RFC 1738 (http://tools.ietf.org/html/rfc1738):
A file URL takes the form:
file://<host>/<path>
where <host> is the fully qualified domain name of the system on
which the <path> is accessible...
As a special case, <host> can be the string "localhost" or the empty
string; this is interpreted as 'the machine from which the URL is
being interpreted'.
Sockets emitted by the 'connection' event are always connected, having
them emit the 'connect' event makes no sense. It only confused people,
as it's not clear if you have to listen to 'connect' or not.
That try..catch block was also very scary. It would silently swallow
exceptions in 'connect' listeners and destroy the socket. Makes no
sense.
Fixes #1047.
Problem: Since stream.pipe() is registering it's own error handlers on
the source and destination stream, it needs to replicate the
EventEmitter 'error' emitting semantics of throwing an error if there
are no other listeners. However, there was a off-by-one error because
the check for remaining listeners was done after cleanup() which means
the pipe's own listener was no longer included.
This would cause 'error' events on either the dest or the source to
throw if there was one other error listener, and while swallowing
the 'error' event if there was no other listener.
Solution: I added a test demonstrating the two issues and fixed the
problem by correcting the off-by-one error.
Fixes #1095.
Problem: It was not possible to detect the reason for a premature
connection termination in http requests.
This patch provides a new `err` argument to the 'close' event which
can be inspected to differentiate between a timeout and a client
actively terminating the connection.
Also contains tests for this new behavior for http and https.
The change for #954 introduced a regression that would cause
the url parser to fail on special chars found in the auth
segment. Fix that, and also don't create invalid urls when
format() is called on an object containing an auth member
containing '@' characters or delimiters.
The debugger would give up after only 100ms but on my system this
timeout isn't enough. The startup process is now modified to try 6
times every 50ms instead.
Fixes #1010.
This fixes a critical bug see in MJR's production. Very difficult to build a
test case. Sometimes HTTPS server gets sockets that are hanging in a
half-duplex state.
This commit does three things:
1. Uses an exposed counter rather than a hidden array for tracking dest
streams that may have multiple inputs. This allows for significantly
faster lookups, since the counter can be checked in constant time rather
than searching an array for the dest object. (A proper O(1) WeakMap
would be better, but that may have to wait for Harmony.)
2. Calls the 'end' event logic when there is an 'error' event on the
source object (and then throws if there are no other error listeners.)
This is important, because otherwise 'error' events would lead to
memory leaks.
3. Clean up the style a bit. Function Declarations are not allowed
within blocks in ES strict. Prefer Function Declarations to Function
Expressions, because hoisting allows for more expressive ordering of
logic.
Downside: It adds "_pipeCount" as part of the Stream API. It'll work
fine if the member is missing, but if anyone tries to use it for some
other purpose, it can mess things up.
1. Allow single-quotes in urls, but escape them.
2. Add comments about which RFCs we're following for guidance.
3. Handle any invalid character in the hostname portion.
4. lcase protocol and hostname portions, since they are
case-insensitive.
Implemented a new property for writable file streams that keeps track
of the bytes written (not queued). This helps when you are piping
another stream to a file, and would like to know how big the file is
without having to issue another stat call.
closes #930
When creating multiple .pipe()s to the same destination stream, the
first source to end would close the destination, breaking all remaining
pipes. This patch fixes the problem by keeping track of all open
pipes, so that we only call end on destinations that have no more
sources piping to them.
closes #929
Previously the return value of write was dependent on if it was paused or
not which was causing a strange error demoed in the previous commit.
Fixes #892
Also, secureOptions flag was added (and passed through) and allows
the context to have all supported SSL_OP_* set via createCredentials.
All SSL_OP_ flags (outside of ALL) have been added to constants.
Problem: Sometimes it is useful to read a file from a certain position
to it's end. The current implementation was already perfectly capable
of this, but decided to throw an error when the user tried to omit
the end option. The only way to do this, was to pass {end: Infinity}.
Solution: Automatically assume {end: Infinity} when omitted, and remove
the previous exception thrown. Also updated the docs.
closes #801.
However, this test is failing for some quite unrelated issue.
Getting some odd "socket hangup" crashes, and only the first request
ever makes it to the server.
Calling resume() immediately after calling pause() would trigger
a race condition where it would try to read() from a file
descriptor that was already being read from, causing an EBADF
setImplementationMethods checks the type of a socket and defines different
behavior based on the type, so auto detect it if type not implicitly
specified.
Since "error" events will throw when unhandled anyhow, it makes no sense
to throw from an EventEmitter's method, especially for such a minor
misdemeanor as attempting to write to a non-writable stream.
This does 3 things:
1. Delimiters and "unwise" characters are never included in the
hostname or path.
2. url.format will sanitize string URLs that are passed to it.
3. The parsed url's 'href' member will be the sanitized url, which may
not match the argument to url.parse.
Since "error" events will throw when unhandled anyhow, it makes no sense
to throw from an EventEmitter's method, especially for such a minor
misdemeanor as attempting to write to a non-writable stream.
Improvements:
* Removes an unnecessary variable
* Avoids having two variables with the same name
* Avoids re-declaring an existing parameter
* Removes an unnecessary ternary operator
* Avoid an inline short-circuit expression for greater clarity.
Problem: Omitting the mode parameter causes the provided callback
parameter to never fire. This was originally fixed in 6078c37b and
later broken in 5f2e9093.
Solution: Overwriting the value of a parameter also overwrites the
reference in the arguments object. This patch works arround this
fact by not touching the mode parameter until a reference to the
callback has been established.
This is important so that in the future, this will work:
$ cd ~/dev/js/some-project
$ npm install redis
$ node
> require.resolve('redis')
'/Users/isaacs/dev/js/some-project/node_modules/redis/index.js'
This works for both ServerResponse and ClientRequest.
Adds three new methods as a couple properties to to OutgoingMessage objects.
Tests by Charlie Robbins.
Change-Id: Ib6f3829798e8f11dd2b6136e61df254f1564807e
This adds support for a cache object to be passed to the
fs.realpath and fs.realpathSync functions. The Module loader keeps an
object around which caches the resulting realpaths that it looks up in
the process of loading modules.
This means that (at least as a result of loading modules) the same files
and folders are never lstat()ed more than once. To reset the cache, set
require("module")._realpathCache to an empty object. To disable the
caching behavior, set it to null.
This allows the various fs utilities and process.umask to be used in
ECMAScript 5 Strict Mode, where the octal literal format is verboten,
without requiring users to litter their code with a bunch of parseInt
calls.
This adds basic support for situations where there is a package.json
with a "main" field. That "main" module is used as the code that is
loaded when the package folder is required.
These are options needed for real-world multicasting.
Implementation notes:
- POSIX only.
- IPv4 only (IPv6 multicast is a tricky beast).
- Didn't update tests, because it can't effectively be demonstrated on
localhost only.
Agent: Each time an http req is sent to a socket, _cycle to try to dispatch
another. Problem became apparent in 4612b0 when we wait for connecting
sockets.