0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
Commit Graph

70 Commits

Author SHA1 Message Date
cjihrig
a73ab9de0d http: remove pointless use of arguments
PR-URL: https://github.com/nodejs/node/pull/10664
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-01-10 14:03:45 -05:00
Brian White
4d7531de24
http: optimize headers iteration
This commit uses instanceof instead of Array.isArray() for faster
type checking and avoids calling Object.keys() when the headers are
stored as a 2D array instead of a plain object.

PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-12-29 14:19:14 -05:00
Brian White
af74e72a9f
http: simplify boolean checks
PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-12-29 14:19:10 -05:00
Brian White
e8b809a7a0
http: extract validation functions
PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-12-29 14:19:07 -05:00
Brian White
b6ea857c7d
lib: avoid recompilation of anonymous functions
Since at least V8 5.4, using function.bind() is now fast enough to
use to avoid recompiling/reoptimizing the same anonymous functions.
These changes especially impact http servers.

PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-12-29 14:19:03 -05:00
Brian White
14c76f8671
http: misc cleanup and minor optimizations
PR-URL: https://github.com/nodejs/node/pull/6533
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-12-29 14:18:53 -05:00
Evan Lucas
d93ab51088 http: add debug message for invalid header value
This makes it easier to see what header has an invalid value.

PR-URL: https://github.com/nodejs/node/pull/9195
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-10-28 09:19:17 -07:00
maasencioh
2ccf601efe http: name anonymous functions in _http_outgoing
Refs: https://github.com/nodejs/node/issues/8913
PR-URL: https://github.com/nodejs/node/pull/9055
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-10-18 15:38:39 -07:00
Brian White
1050594c86
http: fix connection upgrade checks
This commit fixes connection upgrade checks, specifically when headers
are passed as an array instead of a plain object to http.request()

Fixes: https://github.com/nodejs/node/issues/8235
PR-URL: https://github.com/nodejs/node/pull/8238
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-26 10:17:34 -04:00
Franziska Hinkelmann
35109ddaf2 lib: remove double check of string type
checkIsHttpToken() already checks for typeof string. We do not
want to check twice.

PR-URL: https://github.com/nodejs/node/pull/7985
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-08 08:55:26 -07:00
yorkie
99296eedbe http: specify _implicitHeader in OutgoingMessage
PR-URL: https://github.com/nodejs/node/pull/7949
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-08-05 23:26:46 +08:00
Guy Fraser
3c09d1b55f http: replace finish() callback with arrow function
Take advantage of arrow function lexical `this` to avoid defining a
`self = this` var which was only used once.

Code relating to the `finish` event was split in to two areas of the
parent function. Gathered it together to clarify association within the
script.

Fixes: https://github.com/nodejs/node/issues/7295
PR-URL: https://github.com/nodejs/node/pull/7378
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-27 08:26:44 -07:00
Trevor Norris
54cc7212df buffer: introduce latin1 encoding term
When node began using the OneByte API (f150d56) it also switched to
officially supporting ISO-8859-1. Though at the time no new encoding
string was introduced.

Introduce the new encoding string 'latin1' to be more explicit. The
previous 'binary' and documented as an alias to 'latin1'.  While many
tests have switched to use 'latin1', there are still plenty that do both
'binary' and 'latin1' checks side-by-side to ensure there is no
regression.

PR-URL: https://github.com/nodejs/node/pull/7111
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-07 13:51:14 -06:00
Bryan English
31bef6b704 http: correct error message for invalid trailer
Prevent misleading error messages when trailers are invalid.

PR-URL: https://github.com/nodejs/node/pull/6308
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-04-26 22:38:29 -07:00
James M Snell
85ab4a5f12 buffer: add .from(), .alloc() and .allocUnsafe()
Several changes:

* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs

PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2016-03-16 08:34:02 -07:00
Brian White
0223de6ba5 http: remove unnecessary check
The value passed to `process.nextTick()` which is passed to the
callback is already a valid object, so the conditional will always
evaluate to true.

PR-URL: https://github.com/nodejs/node/pull/5233
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-15 07:52:17 -08:00
James M Snell
7bef1b7907 http: strictly forbid invalid characters from headers
PR-URL: https://github.com/nodejs/node-private/pull/26
Reviewed-By: Rod Vagg <r@va.gg>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-09 09:22:09 -08:00
Bo Borgerson
88de88b5a6 http: Remove an unnecessary assignment
This just removes an assignment to `ret` of a value that's not used before
it's overwritten.  Immediately following the assigment is an `if/else` in
which both branches assign to `ret` without using it.

PR-URL: https://github.com/nodejs/node/pull/4323
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-12-17 08:35:59 -08:00
micnic
20285ad177 lib: Consistent error messages in all modules
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-09 20:08:36 +01:00
Ashok Suthar
8625a3815e http: remove unneeded cb check from setTimeout()
- This check is already covered in EventEmitter#addListener()

Refs: https://github.com/nodejs/node/pull/3618
PR-URL: https://github.com/nodejs/node/pull/3631
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-11-05 11:34:31 -05:00
Fedor Indutny
ab03635fb1 http: fix stalled pipeline bug
This is a two-part fix:

- Fix pending data notification in `OutgoingMessage` to notify server
  about flushed data too
- Fix pause/resume behavior for the consumed socket. `resume` event is
  emitted on a next tick, and `socket._paused` can already be `true` at
  this time. Pause the socket again to avoid PAUSED error on parser.

Fix: https://github.com/nodejs/node/issues/3332
PR-URL: https://github.com/nodejs/node/pull/3342
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-10-14 12:16:18 -04:00
Fedor Indutny
184f09dbe4 http: cork/uncork before flushing pipelined res
Make sure that the pipelined response data will be written as less TCP
packets as possible.

PR-URL: https://github.com/nodejs/node/pull/3172
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-10-06 19:41:45 -04:00
James M Snell
0094a8dad7 http: add callback is function check
We were checking that the callback existed, but not
checking that it was a function. In `setTimeout`, if
callback is truthy but not a function, throw a
TypeError

Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
PR-URL: https://github.com/nodejs/node/pull/3090
2015-10-06 14:53:06 -07:00
Fedor Indutny
59cb053394 http: add comment about outputSize in res/server
PR-URL: https://github.com/nodejs/node/pull/3128
2015-10-06 07:03:39 +11:00
Fedor Indutny
b3d96782d4 http_server: pause socket properly
Account pending response data to decide whether pause the socket or
not. Writable stream state is a not reliable measure, because it just
says how much data is pending on a **current** request, thus not helping
much with problem we are trying to solve here.

PR-URL: https://github.com/nodejs/node/pull/3128
2015-10-06 07:02:20 +11:00
Fedor Indutny
05040664c2 http: fix out-of-order 'finish' bug in pipelining
Changes to `stream_base.cc` are required to support empty writes.
Fixes CVE-2015-7384, https://github.com/nodejs/node/issues/3138

Fix: https://github.com/nodejs/node/issues/2639
PR-URL: https://github.com/nodejs/node/pull/3128
2015-10-06 07:02:20 +11:00
James M Snell
6192c9892f http: add checkIsHttpToken check for header fields
Ref: https://github.com/nodejs/node-convergence-archive/issues/13

This adds a new check for header and trailer fields names and method
names to ensure that they conform to the HTTP token rule. If they do
not, a `TypeError` is thrown.

Previously this had an additional `strictMode` option that has been
removed in favor of making the strict check the default (and only)
behavior.

Doc and test case are included.

On the client-side
```javascript
var http = require('http');
var url = require('url');
var p = url.parse('http://localhost:8888');
p.headers = {'testing 123': 123};
http.client(p, function(res) { }); // throws
```

On the server-side
```javascript
var http = require('http');
var server = http.createServer(function(req,res) {
  res.setHeader('testing 123', 123); // throws
  res.end('...');
});
```

Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Trevor Norris <trevnorris@nodejs.org>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
PR-URL: https://github.com/nodejs/node/pull/2526
2015-09-25 08:37:57 -07:00
Ben Noordhuis
e68a119c18 http: guard against response splitting in trailers
Commit 3c293ba ("http: protect against response splitting attacks")
filters out newline characters from HTTP headers but forgot to apply
the same logic to trailing HTTP headers, i.e., headers that come after
the response body.  This commit rectifies that.

The expected security impact is low because approximately no one uses
trailing headers.  Some HTTP clients can't even parse them.

PR-URL: https://github.com/nodejs/node/pull/2945
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Rod Vagg <r@va.gg>
2015-09-18 21:36:27 +02:00
Sakthipriyan Vairamani
9afee6785e http: Check this.connection before using it
Refer: https://github.com/joyent/node/pull/25670

PR-URL: https://github.com/nodejs/io.js/pull/2172
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-07-22 21:44:59 +05:30
Sakthipriyan Vairamani
9cd44bb2b6 util: prepend '(node) ' to deprecation messages
Changes included in this commit are

   1. Making the deprecation messages consistent. The messages will be in
      the following format

           x is deprecated. Use y instead.

      If there is no alternative for `x`, then the ` Use y instead.` part
      will not be there in the message.

   2. All the internal deprecation messages are printed with the prefix
      `(node) `, except when the `--trace-deprecation` flag is set.

Fixes: https://github.com/nodejs/io.js/issues/1883
PR-URL: https://github.com/nodejs/io.js/pull/1892
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-07-03 16:32:29 +02:00
Roman Reiss
b5b8ff117c lib: don't use global Buffer
Port of https://github.com/joyent/node/pull/8603

The race condition present in the original PR didn't occur, so no
workaround was needed.

PR-URL: https://github.com/nodejs/io.js/pull/1794
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-06-11 20:24:44 +02:00
Vladimir Kurchatkin
2c686fd3ce http: flush stored header
`flushHeaders` should work for header written
with `writeHead`.

PR-URL: https://github.com/nodejs/io.js/pull/1695
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-29 16:19:12 +03:00
Brian White
1eec5f091a http: simplify code and remove unused properties
PR-URL: https://github.com/nodejs/io.js/pull/1572
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-05-25 01:07:22 -04:00
Evan Lucas
d4726cde57 http,net,tls: return this from setTimeout methods
Modifies the setTimeout methods for the following prototypes:

- http.ClientRequest
- http.IncomingMessage
- http.OutgoingMessage
- http.Server
- https.Server
- net.Socket
- tls.TLSSocket

Previously, the above functions returned undefined. They now return
`this`. This is useful for chaining function calls.

PR-URL: https://github.com/nodejs/io.js/pull/1699
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-05-16 07:17:41 +02:00
Yosuke Furukawa
19ffb5cf1c lib: fix eslint styles
PR-URL: https://github.com/iojs/io.js/pull/1539
Fixes: https://github.com/iojs/io.js/issues/1253
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-09 12:10:02 +09:00
Trevor Norris
10e31ba56c node: allow multiple arguments passed to nextTick
PR-URL: https://github.com/iojs/io.js/pull/1077
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-15 17:02:21 -06:00
Yosuke Furukawa
b2e00e38dc http: add flushHeaders and deprecate flush
PR-URL: https://github.com/iojs/io.js/pull/1156
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-03-17 00:54:11 +01:00
Christian Tellnes
4874182065 http: send Content-Length when possible
This changes the behavior for http to send send a Content-Length header
instead of using chunked encoding when we know the size of the body when
sending the headers.

Fixes: https://github.com/iojs/io.js/issues/1044
PR-URL: https://github.com/iojs/io.js/pull/1062
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Brian White <mscdex@mscdex.net>
2015-03-05 22:17:35 +01:00
Brendan Ashworth
08133f45c7 http: optimize outgoing requests
This commit does some small optimization changes on
`lib/_http_outgoing.js`. These include switching from `while` loops to
`for` loops, moving away from `util` to `typeof` checks, and removing
dead code. It also includes variable caches to avoid lookups and
generic style changes. All in all, much faster execution.

It gets an across the board increase in req/sec on the benchmarks,
from my experience about a 10% increase.

PR-URL: https://github.com/iojs/io.js/pull/605
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Nicu Micleușanu <micnic90@gmail.com>
Reviewed-By: Christian Vaagland Tellnes <christian@tellnes.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2015-03-03 21:53:58 -08:00
Christian Tellnes
675cffb33e http: don't confuse automatic headers for others
If you set a custom http header which includes eg. the string `Date`,
then http will not automatically send the `Date` header.

This is also true for other automatic http headers.

PR-URL: https://github.com/iojs/io.js/pull/828
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-02-27 21:47:39 -08:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).

Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31 23:47:29 -05:00
Qasim Zaidi
cf3e908b70 http: more descriptive setHeader errors
PR-URL: https://github.com/iojs/io.js/pull/480
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2015-01-29 16:58:36 -08:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01:00
Trevor Norris
979d0ca874 http: cleanup setHeader()
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>
2014-09-29 12:32:42 -07:00
Julien Gilli
64d6de9f34 http: write() after end() emits an error.
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>
2014-09-23 11:54:26 +04:00
Timothy J Fontaine
7ca5af87a0 Merge remote-tracking branch 'upstream/v0.10' into v0.12
Conflicts:
	ChangeLog
	deps/v8/src/hydrogen.cc
	lib/http.js
	lib/querystring.js
	src/node_crypto.cc
	src/node_version.h
	test/simple/test-querystring.js
2014-09-16 17:48:09 -07:00
Ben Noordhuis
bd24ab2bd7 http: add request.flush() method
Forcibly flushes the request headers.  You need this with long-lived
HTTP connections where the first data isn't written until the connection
has been established (think: tunneling requests over HTTP CONNECT.)

Fixes #7296.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-04-24 10:43:51 +04:00
Yuki KAN
006d42786e lib: use triple equals
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-04-02 02:12:18 -07:00