0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

359 Commits

Author SHA1 Message Date
isaacs
88644eaa2d stream: There is no _read cb, there is only push
This makes it so that `stream.push(chunk)` is the only way to signal the
end of reading, removing the confusing disparity between the
callback-style _read method, and the fact that most real-world streams
do not have a 1:1 corollation between the "please give me data" event,
and the actual arrival of a chunk of data.

It is still possible, of course, to implement a `CallbackReadable` on
top of this.  Simply provide a method like this as the callback:

    function readCallback(er, chunk) {
      if (er)
        stream.emit('error', er);
      else
        stream.push(chunk);
    }

However, *only* fs streams actually would behave in this way, so it
makes not a lot of sense to make TCP, TLS, HTTP, and all the rest have
to bend into this uncomfortable paradigm.
2013-02-28 17:38:17 -08:00
Ben Noordhuis
cb87920ba9 Merge remote-tracking branch 'origin/v0.8'
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/src/unix/pipe.c
	lib/http.js
	src/node_version.h
2013-02-28 16:58:24 +01:00
Ben Noordhuis
d4a297ccb0 http: fix case in 505 response status line
Fixes #4850.
2013-02-26 15:18:40 +01:00
isaacs
b0e7dbf2c0 http: Do not free the wrong parser on socket close
This appears to fix #4673.  That bug is very hard to reproduce, so it's
hard to tell for certain, but this approach is more correct anyway.

Hat-tip: @dougwilson
2013-02-25 09:06:46 -08:00
isaacs
f9a0140ef1 http: Handle hangup writes more gently 2013-02-22 10:35:07 -08:00
isaacs
09b1212254 http: Add fixme comment about ECONNRESET handling 2013-02-18 10:38:37 -08:00
isaacs
d75e39794b Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	lib/http.js
	src/node_version.h
	test/simple/test-http-header-response-splitting.js
2013-02-18 10:21:08 -08:00
isaacs
987338fe31 http: Do not let Agent hand out destroyed sockets
Fix #4373
2013-02-14 16:03:40 -08:00
isaacs
c9dcf5718c http: Raise hangup error on destroyed socket write
Prior to v0.10, Node ignored ECONNRESET errors in many situations.
There *are* valid cases in which ECONNRESET should be ignored as a
normal part of the TCP dance, but in many others, it's a very relevant
signal that must be heeded with care.

Exacerbating this problem, if the OutgoingMessage does not have a
req.connection._handle, it assumes that it is in the process of
connecting, and thus buffers writes up in an array.

The problem happens when you reuse a socket between two requests, and it
is destroyed abruptly in between them.  The writes will be buffered,
because the socket has no handle, but it's not ever going to GET a
handle, because it's not connecting, it's destroyed.

The proper fix is to treat ECONNRESET correctly.  However, this is a
behavior/semantics change, and cannot land in a stable branch.

Fix #4775
2013-02-14 16:03:40 -08:00
Bert Belder
255bc945c2 http: protect against response splitting attacks
This patch is a back-port of 3c293ba.
Closes #4696
2013-02-07 14:39:47 +01:00
isaacs
faf78604ca http: Don't dump twice 2013-01-28 08:54:08 -08:00
Ben Noordhuis
4a7a98fd0a http: close connection on 204 and chunked encoding
This is similar to commit 2cbf458 but this time for 204 No Content
instead of 304 Not Modified responses.

When the user sends a 204 response with a Transfer-Encoding: chunked
header, suppress sending the zero chunk and force the connection to
close.
2013-01-24 11:23:36 +01:00
Ben Noordhuis
2cbf4586df http: close connection on 304 and chunked encoding
Force the connection to close when the response is a 304 Not Modified
and the user has set a "Transfer-Encoding: chunked" header.

RFC 2616 mandates that 304 responses MUST NOT have a body but node.js
used to send out a zero chunk anyway to accommodate clients that don't
have special handling for 304 responses.

It was pointed out that this might confuse reverse proxies to the point
of creating security liabilities, so suppress the zero chunk and force
the connection to close.
2013-01-23 01:47:24 +01:00
isaacs
3d7818fc42 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	src/node_version.h
	test/simple/test-buffer.js
2013-01-18 12:58:16 -08:00
Alexandr Emelin
eef0ccbcaf http: fix duplicate var initialization
IncomingMessage function contained duplicate initialization
of this._pendings. Line with one of those expressions has been
removed.
2013-01-16 17:10:14 +01:00
Ben Noordhuis
f3e78bd3c2 http: fix "Cannot call method 'emit' of null"
Fix the following exception:

  http.js:974
    this._httpMessage.emit('close');
                      ^
  TypeError: Cannot call method 'emit' of null
      at Socket.onServerResponseClose (http.js:974:21)
      at Socket.EventEmitter.emit (events.js:124:20)
      at net.js:421:10
      at process._tickCallback (node.js:386:13)
      at process._makeCallback (node.js:304:15)

Fixes #4586.
2013-01-14 17:28:32 +01:00
isaacs
dc0c524ce6 http: Set _dumped=false initially
The better to keep the IncomingMessage class isomorphic and avoid
creating additional hidden classes.
2013-01-10 18:16:43 -08:00
isaacs
9ece63b1d7 http: Don't switch the socket into old-mode 2013-01-10 13:50:06 -08:00
isaacs
bc8feb151c http: Use stream.push() instead of touching _readableState 2013-01-10 13:50:06 -08:00
isaacs
f423287453 http: Separate out the storeHeader closure 2012-12-29 15:32:25 -08:00
isaacs
9785ab6057 http: Replace "in" usage with "=== undefined"
Speeds up http benchmarks.
2012-12-29 15:32:25 -08:00
Ryunosuke SATO
8936868e9b http: remove unused variable
The module variable `END_OF_FILE` was no longer needed from 1d369317.
2012-12-27 15:09:04 -08:00
isaacs
d76eacd4e6 http: Handle end only when stream is not dumped
This fixes regression introduced in some cases by 8bf0c15
2012-12-26 15:57:49 -08:00
isaacs
54740c8b24 lint 2012-12-26 15:26:53 -08:00
Shigeki Ohtsu
8bf0c15a5b stream2: fix to emit end event on http.ClientResponse 2012-12-26 15:20:48 -08:00
isaacs
fb915ed957 lint 2012-12-21 16:51:43 +00:00
isaacs
c048c814c7 http: Trivial fix for comments and 'this.read' 2012-12-21 16:48:32 +00:00
isaacs
8624adf5d8 http: use IncomingMessage._dump() instead of resume() 2012-12-21 00:07:34 +00:00
Ben Noordhuis
79ae8b7ae2 Merge remote-tracking branch 'origin/v0.8' 2012-12-20 12:39:04 +01:00
Ben Noordhuis
5a19c07c08 http: pack response body buffer in first tcp packet
Apply the same optimization to res.end(buf) that is applied to res.end(str).

Speeds up `node benchmark/http_simple_auto -k -c 1 -n 25000 buffer/1`
(non-chunked response body) by about 750x. That's not a typo.

Chunked responses:

  $ cat tmp/http-chunked-client.js
  // Run `node benchmark/http_simple` in another terminal.
  var http = require('http'), url = require('url');
  var options = url.parse('http://127.0.0.1:8000/buffer/1/1');
  options.agent = new http.Agent({ maxSockets: 1 });
  for (var i = 0; i < 25000; ++i) http.get(options);

Before:

  $ time out/Release/node tmp/http-chunked-client.js
  real    16m40.411s
  user    0m9.184s
  sys     0m0.604s

After:

  $ time out/Release/node tmp/http-chunked-client.js
  real    0m5.386s
  user    0m2.768s
  sys     0m0.728s

That's still a 185x speed-up.

Fixes #4415.
2012-12-20 12:02:06 +01:00
Brian White
827b2a9b0b http: bubble up parser errors to ClientRequest
Make parser errors bubble up to the ClientRequest instead of the underlying
net.Socket object.

This is a back-port of commit c78678b from the master branch.

Fixes #3776.
2012-12-16 17:25:03 +01:00
isaacs
1d369317ea http: Refactor for streams2
Because of some of the peculiarities of http, this has a bit of special
magic to handle cases where the IncomingMessage would wait forever in a
paused state.

In the server, if you do not begin consuming the request body by the
time the response emits 'finish', then it will be flushed out.

In the client, if you do not add a 'response' handler onto the request,
then the response stream will be flushed out.
2012-12-14 17:46:23 -08:00
Bert Belder
3c293ba272 http: protect against response splitting attacks 2012-12-07 17:13:51 -08:00
Scott Blomquist
f657ce685d windows: add tracing with performance counters
Patch by Henry Rawas and Scott Blomquist.
2012-11-21 01:21:53 +01:00
isaacs
8509073458 lint 2012-10-12 11:46:36 -07:00
isaacs
061f2075cf string_decoder: Add 'end' method, do base64 properly 2012-10-11 16:46:18 -07:00
Ben Noordhuis
0ad005852c https: fix renegotation attack protection
Listen for the 'clientError' event that is emitted when a renegotation attack
is detected and close the connection.

Fixes test/pummel/test-https-ci-reneg-attack.js
2012-10-09 16:38:00 +02:00
isaacs
836a06fc4f Revert "http: make http.ServerResponse emit 'end'"
This reverts commit 790d651f0d.

This makes Duplex streams unworkable, and would only ever be a special
case for HTTP responses, which is not ideal.

Intead, we're going to just bless the 'finish' event for all Writable
streams in 0.10
2012-10-03 17:40:14 -07:00
isaacs
ae40f1c438 Merge remote-tracking branch 'ry/v0.8' into v0.8-merge
Conflicts:
	AUTHORS
	ChangeLog
	deps/openssl/openssl.gyp
	deps/uv/src/unix/linux/linux-core.c
	deps/uv/src/unix/process.c
	deps/uv/src/unix/stream.c
	deps/v8/src/arm/builtins-arm.cc
	deps/v8/src/arm/code-stubs-arm.cc
	deps/v8/src/arm/full-codegen-arm.cc
	lib/tls.js
	src/node_version.h
	test/simple/test-http-client-timeout-agent.js
2012-09-28 09:47:48 -07:00
Pavel Lang
b38277be26 http: add response.headersSent property
Boolean property getter. True if headers was sent, false otherwise.
2012-09-28 02:57:01 +02:00
thewilli
33a5c8a814 http: handle multiple Proxy-Authenticate values
Just as the 'WWW-Authenticate' HTTP header the 'Proxy-Authenticate' header might
be received several times as well. Currently only one value is preserved. This
change allows to receive multiple values concatenated by space and comma.
2012-09-27 13:28:16 -07:00
thewilli
ac17dc1764 http: handle multiple Proxy-Authenticate values
Just as the 'WWW-Authenticate' HTTP header the 'Proxy-Authenticate' header might
be received several times as well. Currently only one value is preserved. This
change allows to receive multiple values concatenated by space and comma.
2012-09-27 01:11:00 +02:00
Nathan Rajlich
0f2ed2bc2c http: make the client "res" object gets the same domain as "req"
Fixes #4046.
2012-09-24 11:48:39 -07:00
isaacs
bb207c2827 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	ChangeLog
	src/node_version.h
	test/simple/test-util-inspect.js
2012-09-12 15:13:07 -07:00
Frédéric Germain
451ff1540a http: Remove timeout handler when data arrives 2012-09-12 09:50:06 -07:00
Ben Noordhuis
9a3521cb25 http: respect HTTP/1.0 TE header
A HTTP/1.0 client does not support 'Transfer-Encoding: chunked' unless it
explicitly requests it by sending a 'TE: chunked' header.

Before this commit, node.js always disabled chunked encoding for HTTP/1.0
clients. Now it will scan for the TE header and turn on chunked encoding if
requested and applicable.

Fixes #940.
2012-09-08 21:43:57 +02:00
Ben Noordhuis
790d651f0d http: make http.ServerResponse emit 'end'
This used to be the internal 'finish' event. Make it public so API users will
know when the response has been sent completely.

Fixes #3855.
2012-09-04 22:07:48 +02:00
Brian White
c78678b081 http: bubble up parser errors to ClientRequest
Make parser errors bubble up to the ClientRequest instead of the underlying
net.Socket object.

Fixes #3776.
2012-08-24 17:26:31 +02:00
isaacs
b0c0111b04 https: Use host header as effective servername 2012-07-25 13:38:43 -07:00
Brian White
e06b5d7af7 http: remove duplicate assignments
Closes GH-3754
2012-07-23 11:35:52 +02:00