Match the behavior of the slow path by setting url.query to an empty
object when the url contains no query, but query parsing is requested.
Also add a test for this case, and update the documents to clearly
reflect this behavior.
Fixes: https://github.com/joyent/node/issues/8332
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Running fill() with an empty string would cause Node to hang
indefinitely. Now it will return without having operated on the buffer.
User facing function has been pulled into JS to perform all initial
value checks and coercions. The C++ method has been placed on the
"internal" object.
Coerced non-string values to numbers to match v0.10 support.
Simplified logic and changed a couple variable names.
Added tests for fill() and moved them all to the beginning of
buffer-test.js since many other tests depend on fill() working properly.
Fixes: https://github.com/joyent/node/issues/8469
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Several fields on OutgoingMessage were set after instantiation. These
have been included in the constructor to prevent mutation of the object
map after instantiation.
"name" is now explicitly checked to be a string. Where before if a
non-string was passed the following cryptic error was thrown:
_http_outgoing.js:334
var key = name.toLowerCase();
^
TypeError: undefined is not a function
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Add stricter argument type checking to normalizeSpawnArguments().
Removes a number of extraneous checks in spawn().
Fix regression in handling of the optional args argument.
Add more thorough testing of spawn() arguments.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Only run lineEnding.test() on the newly acquired chunk of string instead
of on the entire line buffer.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
The property server.connections should no longer be enumerable because
it has been deprecated. This will prevent deprecation warnings when
server objects are accessed by functions such as JSON.stringify.
Fixes: https://github.com/joyent/node/issues/8373
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
In 4c9b30d removal of the prototype attributes meant NativeBuffer() no
longer had the same object map as Buffer(). By now setting the same
properties in the same order both constructors will produce the same
map.
The same commit changed "parent" from undefined to null. This caused a
failure in Buffer#slice() where it was checked if parent === undefined.
Causing the incorrect parent to be set.
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
When calling write() after end() has been called on an OutgoingMessage,
an error is emitted and the write's callback is called with an instance
of Error.
Fix#7477.
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Increase the performance of new Buffer construction by initializing all
properties before SetIndexedPropertiesToExternalArrayData call.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
When replying to a HEAD request, do not attempt to send the trailers and
EOF sequence (`0\r\n\r\n`). The HEAD request MUST not have body.
Quote from RFC:
The presence of a message body in a response depends on both the
request method to which it is responding and the response status code
(Section 3.1.2). Responses to the HEAD request method (Section 4.3.2
of [RFC7231]) never include a message body because the associated
response header fields (e.g., Transfer-Encoding, Content-Length,
etc.), if present, indicate only what their values would have been if
the request method had been GET (Section 4.3.1 of [RFC7231]).
fix#8361
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Compiles and executes source code in V8's debugger context. Provides
a programmatic way to get access to the debug object by executing:
var Debug = vm.runInDebugContext('Debug');
Fixes#7886.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Unexport the http.parsers freelist. It was originally exported by Ryan
in commit 0003c701 but the commit log doesn't mention why and it's never
been documented. It's unclear if there are any users.
The lifecycle of parser objects changed recently and it seems better to
not let people shoot themselves in the foot so easily.
If it turns out there are actually users, we can always re-export it
again - probably under a slightly different name, to force people to
update their code to the new way of things.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Make it a little harder to slip in use-after-free bugs by nulling out
references to the parser object after handing it off to freeParser().
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Weak handles put strain on the garbage collector and the parser handle
doesn't need to be weak in the first place. This change should improve
GC times on busy servers a little.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Allow cluster workers to listen on exclusive ports for TCP and UDP,
instead of forcing all calls to go through the cluster master.
Fixes: #3856
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
node::StringBytes::Write() has appropriate support to write strings with
'binary' encoding. So expose that API through StreamWrap and allow
inheriting classes to use it.
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Currently, cluster workers can be removed from the workers list in three
different places:
- In the exit event handler for the worker process.
- In the disconnect event handler of the worker process.
- In the disconnect event handler of the cluster master.
However, handles for a given worker are cleaned up only in one of these
places: in the cluster master's disconnect event handler.
Because these events happen asynchronously, it is possible that the
workers list is empty before we even clean up one handle. This makes
the assert that makes sure that no handle is left when the workers
list is empty fail.
This commit removes the worker from the cluster.workers list only when
the worker is dead _and_ disconnected, at which point we're sure that
its associated handles are cleaned up.
Fixes#8191 and #8192.
Reviewed-By: Fedor Indutny <fedor@indutny.com>
In case of an invalid DH parameter file, it is sliently discarded. To
use auto DH parameter in a server and DHE key length check in a
client, we need to wait for the next release of OpenSSL-1.0.2.
Reviewed-By: Fedor Indutny <fedor@indutny.com>
There is no need to split the host by hand in `url.js` – Punycode.js
takes care of it anyway. This not only simplifies the code, but also
adds support for RFC 3490 separators (i.e. not just U+002E, but U+3002,
U+FF0E, and U+FF61 as well).
Closes#6055.
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Documentation states that `querystring.unescape` may be overridden to
replace unescaper during parsing. However, the function was only
being used as a fallback for when the native decoder throws (on a
malformed URL). This patch moves the call to the native function and
the try/catch around it into querystring.unescape then has the parser
always invoke it, so that an override will always be used.
Fixes#4055
Reviewed-By: Fedor Indutny <fedor@indutny.com>
net Sockets were calling read(0) to start reading, without
checking to see if they were paused first. This would result
in paused Socket objects keeping the event loop alive.
Fixes#8200
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Fix assertion failure from poor argument parsing logic introduced in
6ea5d16. Add tests to make sure arguments are properly parsed.
Fixes: 6ea5d16 "dns: always set variable family in lookup()"
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Fixes an issue that caused the first querystring to be parsed prepending
a "?" in the first variable name on relative urls with no #fragment
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Regression occurred that prevented the variable "family" from being set
properly when the lookup() function's "options" parameter was passed a
number instead of an object.
Also included a sanity check by setting the default value of "family" to
a value that will not pass verification.
Fixes: e643fe4 "dns: fix GetAddrInfo assert"
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This is the Node side of the fix for Node's cluster module on Windows.
https://github.com/joyent/node/issues/7691
The other required part is
https://github.com/joyent/libuv/pull/1384
Windows and Unix return certain socket errors (i.e. EADDRINUSE) at
different times: bind on Windows, and listen on Unix.
In an effort to hide this difference, libuv on Windows stores such
errors in the bind_error field of uv_tcp_t, to defer raising it at
listen time.
This worked fine except for the case in which a socket is shared in
a Node cluster and a bind error occurs.
A previous attempt to fix this (
d1e6be14603da36fe00e
) was flawed becaused in an attempt to relay the error at the JS level
it caused the master to start accepting connections.
With this new approach, libuv itself is relaying the bind errors,
providing for a uniform behavior of uv_tcp_listen.
Reviewed-By: Fedor Indutny <fedor@indutny.com>
The method GetAddrInfo() is used by more than just dns.lookup(), and in
those cases a third argument isn't passed. This caused the following
check to abort:
assert(args[3]->IsInt32());
Fixes: 4306786 "net: don't prefer IPv4 addresses during resolution"
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Currently the address resolution family defaults to IPv4. Instead remove
the preference and instead resolve to a family suitable for the host.
Expose the getaddrinfo flags and allow them to be passed.
Add documentation about new flags.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
On Windows, path.isAbsolute() returns an empty string on failed cases.
This forces the return value to always be boolean.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Callbacks in node are usually asynchronous, and should never be
sometimes synchronous, and sometimes asynchronous.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Internal function trim(arr). 2nd parameter of slice() should be slice's
end index (not included). Because of function normalize() (called before
trim()), "start" is always zero so the bug -for now- has no effect, but
its a bug waiting to happen.
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
A streams1 stream will have its falsy values such as 0, false, or ""
eaten by the upgrade to streams2, even when objectMode is enabled.
Include test for said cases.
Reviewed-by: isaacs <i@izs.me>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>