summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_incoming.js5
-rw-r--r--lib/_http_outgoing.js24
-rw-r--r--lib/_http_server.js14
-rw-r--r--lib/_stream_readable.js25
-rw-r--r--lib/_tls_legacy.js4
-rw-r--r--lib/child_process.js14
-rw-r--r--lib/events.js10
-rw-r--r--lib/fs.js24
-rw-r--r--lib/internal/http2/core.js11
-rw-r--r--lib/path.js18
-rw-r--r--lib/querystring.js5
-rw-r--r--lib/url.js16
12 files changed, 76 insertions, 94 deletions
diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js
index 6e5aff1cc9..696fcc3b4c 100644
--- a/lib/_http_incoming.js
+++ b/lib/_http_incoming.js
@@ -301,10 +301,9 @@ function _addHeaderLine(field, value, dest) {
} else {
dest['set-cookie'] = [value];
}
- } else {
+ } else if (dest[field] === undefined) {
// Drop duplicates
- if (dest[field] === undefined)
- dest[field] = value;
+ dest[field] = value;
}
}
diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js
index e9e0c04270..76d83b1921 100644
--- a/lib/_http_outgoing.js
+++ b/lib/_http_outgoing.js
@@ -404,20 +404,18 @@ function _storeHeader(firstLine, headers) {
this.chunkedEncoding = false;
} else if (!this.useChunkedEncodingByDefault) {
this._last = true;
+ } else if (!state.trailer &&
+ !this._removedContLen &&
+ typeof this._contentLength === 'number') {
+ state.header += 'Content-Length: ' + this._contentLength + CRLF;
+ } else if (!this._removedTE) {
+ state.header += 'Transfer-Encoding: chunked\r\n';
+ this.chunkedEncoding = true;
} else {
- if (!state.trailer &&
- !this._removedContLen &&
- typeof this._contentLength === 'number') {
- state.header += 'Content-Length: ' + this._contentLength + CRLF;
- } else if (!this._removedTE) {
- state.header += 'Transfer-Encoding: chunked\r\n';
- this.chunkedEncoding = true;
- } else {
- // We should only be able to get here if both Content-Length and
- // Transfer-Encoding are removed by the user.
- // See: test/parallel/test-http-remove-header-stays-removed.js
- debug('Both Content-Length and Transfer-Encoding are removed');
- }
+ // We should only be able to get here if both Content-Length and
+ // Transfer-Encoding are removed by the user.
+ // See: test/parallel/test-http-remove-header-stays-removed.js
+ debug('Both Content-Length and Transfer-Encoding are removed');
}
}
diff --git a/lib/_http_server.js b/lib/_http_server.js
index a133c2c153..cb949cb07e 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -433,8 +433,8 @@ function socketOnEnd(server, socket, parser, state) {
state.outgoing[state.outgoing.length - 1]._last = true;
} else if (socket._httpMessage) {
socket._httpMessage._last = true;
- } else {
- if (socket.writable) socket.end();
+ } else if (socket.writable) {
+ socket.end();
}
}
@@ -602,13 +602,11 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
res.writeContinue();
server.emit('request', req, res);
}
+ } else if (server.listenerCount('checkExpectation') > 0) {
+ server.emit('checkExpectation', req, res);
} else {
- if (server.listenerCount('checkExpectation') > 0) {
- server.emit('checkExpectation', req, res);
- } else {
- res.writeHead(417);
- res.end();
- }
+ res.writeHead(417);
+ res.end();
}
} else {
server.emit('request', req, res);
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index b031bf0b75..78732ed185 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -40,20 +40,19 @@ const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
function prependListener(emitter, event, fn) {
// Sadly this is not cacheable as some libraries bundle their own
// event emitter implementation with them.
- if (typeof emitter.prependListener === 'function') {
+ if (typeof emitter.prependListener === 'function')
return emitter.prependListener(event, fn);
- } else {
- // This is a hack to make sure that our error handler is attached before any
- // userland ones. NEVER DO THIS. This is here only because this code needs
- // to continue to work with older versions of Node.js that do not include
- // the prependListener() method. The goal is to eventually remove this hack.
- if (!emitter._events || !emitter._events[event])
- emitter.on(event, fn);
- else if (Array.isArray(emitter._events[event]))
- emitter._events[event].unshift(fn);
- else
- emitter._events[event] = [fn, emitter._events[event]];
- }
+
+ // This is a hack to make sure that our error handler is attached before any
+ // userland ones. NEVER DO THIS. This is here only because this code needs
+ // to continue to work with older versions of Node.js that do not include
+ // the prependListener() method. The goal is to eventually remove this hack.
+ if (!emitter._events || !emitter._events[event])
+ emitter.on(event, fn);
+ else if (Array.isArray(emitter._events[event]))
+ emitter._events[event].unshift(fn);
+ else
+ emitter._events[event] = [fn, emitter._events[event]];
}
function ReadableState(options, stream) {
diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js
index 5f83c528b1..07b95546b3 100644
--- a/lib/_tls_legacy.js
+++ b/lib/_tls_legacy.js
@@ -878,8 +878,8 @@ SecurePair.prototype.error = function(returnOnly) {
/peer did not return a certificate/.test(err.message)) {
// Not really an error.
this.destroy();
- } else {
- if (!returnOnly) this.cleartext.emit('error', err);
+ } else if (!returnOnly) {
+ this.cleartext.emit('error', err);
}
return err;
};
diff --git a/lib/child_process.js b/lib/child_process.js
index 3bf3b23a1c..d9e11cb9a7 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -324,11 +324,10 @@ exports.execFile = function(file /*, args, options, callback*/) {
if (stdoutLen > options.maxBuffer) {
ex = new Error('stdout maxBuffer exceeded');
kill();
+ } else if (encoding) {
+ _stdout += chunk;
} else {
- if (encoding)
- _stdout += chunk;
- else
- _stdout.push(chunk);
+ _stdout.push(chunk);
}
});
}
@@ -343,11 +342,10 @@ exports.execFile = function(file /*, args, options, callback*/) {
if (stderrLen > options.maxBuffer) {
ex = new Error('stderr maxBuffer exceeded');
kill();
+ } else if (encoding) {
+ _stderr += chunk;
} else {
- if (encoding)
- _stderr += chunk;
- else
- _stderr.push(chunk);
+ _stderr.push(chunk);
}
});
}
diff --git a/lib/events.js b/lib/events.js
index 1414a1429d..c7bd15dc5b 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -280,13 +280,11 @@ function _addListener(target, type, listener, prepend) {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
- } else {
// If we've already got an array, just append.
- if (prepend) {
- existing.unshift(listener);
- } else {
- existing.push(listener);
- }
+ } else if (prepend) {
+ existing.unshift(listener);
+ } else {
+ existing.push(listener);
}
// Check for listener leak
diff --git a/lib/fs.js b/lib/fs.js
index 32a0ea8a49..e1407ba4f1 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1262,21 +1262,19 @@ function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {
callback(writeErr);
});
}
- } else {
- if (written === length) {
- if (isUserFd) {
- callback(null);
- } else {
- fs.close(fd, callback);
- }
+ } else if (written === length) {
+ if (isUserFd) {
+ callback(null);
} else {
- offset += written;
- length -= written;
- if (position !== null) {
- position += written;
- }
- writeAll(fd, isUserFd, buffer, offset, length, position, callback);
+ fs.close(fd, callback);
+ }
+ } else {
+ offset += written;
+ length -= written;
+ if (position !== null) {
+ position += written;
}
+ writeAll(fd, isUserFd, buffer, offset, length, position, callback);
}
});
}
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 663672f052..5eb34ecdfd 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -187,12 +187,11 @@ function onSessionHeaders(id, cat, flags, headers) {
}
} else if (cat === NGHTTP2_HCAT_PUSH_RESPONSE) {
event = 'push';
- } else { // cat === NGHTTP2_HCAT_HEADERS:
- if (!endOfStream && status !== undefined && status >= 200) {
- event = 'response';
- } else {
- event = endOfStream ? 'trailers' : 'headers';
- }
+ // cat === NGHTTP2_HCAT_HEADERS:
+ } else if (!endOfStream && status !== undefined && status >= 200) {
+ event = 'response';
+ } else {
+ event = endOfStream ? 'trailers' : 'headers';
}
debug(`[${sessionName(owner[kType])}] emitting stream '${event}' event`);
process.nextTick(emit, stream, event, obj, flags, headers);
diff --git a/lib/path.js b/lib/path.js
index 876e5fd582..e8dbf4c2ee 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -455,17 +455,15 @@ const win32 = {
} else {
return '';
}
+ } else if (isAbsolute) {
+ if (tail.length > 0)
+ return device + '\\' + tail;
+ else
+ return device + '\\';
+ } else if (tail.length > 0) {
+ return device + tail;
} else {
- if (isAbsolute) {
- if (tail.length > 0)
- return device + '\\' + tail;
- else
- return device + '\\';
- } else if (tail.length > 0) {
- return device + tail;
- } else {
- return device;
- }
+ return device;
}
},
diff --git a/lib/querystring.js b/lib/querystring.js
index b4851f57c3..936b7463c9 100644
--- a/lib/querystring.js
+++ b/lib/querystring.js
@@ -315,9 +315,8 @@ function parse(qs, sep, eq, options) {
sepIdx = eqIdx = 0;
continue;
}
- } else {
- if (lastPos < end)
- value += qs.slice(lastPos, end);
+ } else if (lastPos < end) {
+ value += qs.slice(lastPos, end);
}
if (key.length > 0 && keyEncoded)
diff --git a/lib/url.js b/lib/url.js
index b1e0ff8da5..72e03e0f9c 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -128,16 +128,14 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
if (isWs)
continue;
lastPos = start = i;
- } else {
- if (inWs) {
- if (!isWs) {
- end = -1;
- inWs = false;
- }
- } else if (isWs) {
- end = i;
- inWs = true;
+ } else if (inWs) {
+ if (!isWs) {
+ end = -1;
+ inWs = false;
}
+ } else if (isWs) {
+ end = i;
+ inWs = true;
}
// Only convert backslashes while we haven't seen a split character