An overloaded toString() method may have side effects so don't call it for a simple type check. Back-port of 54b409d to the v0.4 branch.
During write(), _hasBody is checked to make sure a body is allowed -- this is now also checked during end(body) when write() isn't used. Concise final chunk for HEAD req's res.end(data). Instead of simply clearing data, check _hasBody earlier to avoid sending cruft when chunkedEncoding is used. Fixes #1291.
Thanks to Yann Biancheri for putting together an initial test.
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'.
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.