Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

HTTP end event not fired #5566

Closed
azcoffeehabit opened this issue May 26, 2013 · 2 comments
Closed

HTTP end event not fired #5566

azcoffeehabit opened this issue May 26, 2013 · 2 comments

Comments

@azcoffeehabit
Copy link

After upgrade to 10.8 http end events are not fired (was working in 8.x). See following code:

var http = require("http");
var port = 8888;

function startServer(route, handle) {
    function onRequest(request, response) {
        console.log("Request received.");

        request.setEncoding("utf8");

        if(request.method == 'POST') {
            request.addListener("data", function(postDataChunk) {
                console.log("Received POST data chunk '"+ postDataChunk + "'.");
            }); 
        }
        else {
            console.log(request.method + " request received");
        }

        request.on('end', function () {
            console.log("end request received");
        });

        request.on('error', function () {
            console.log("There was an error event");
        });
    }

    var server = http.createServer(onRequest).listen(port);
}
startServer();

TESTS

test 1: standard GET request

$ curl localhost:8888

console:
Request received.
GET request received

test 2: standard POST with data

$ curl localhost:8888 -d 'test'

console:
Request received.
Received POST data chunk 'test'.
end request received

test 3: GET with data

$ curl localhost:8888 -G -d 'test'

node console:
Request received.
GET request received

@tjfontaine
Copy link

This is working as expected, it's a by product of the streams2 work the stream won't start reading until you tell it to. You initiate reading by:

  • piping the stream somewhere req.pipe()
  • resuming the stream req.resume()
  • switching into old mode req.on('data')

In your example you're only switching into old mode when it's a POST

@azcoffeehabit
Copy link
Author

Thank you so much. Makes perfect sense now!

gibfahn pushed a commit to ibmruntimes/node that referenced this issue May 6, 2016
Addresses nodejs#5566. The `ee.once()` function is currently documented as
invoking the listener, and then removing it when the event is
triggered. However, this is not really the case. The listener is removed
and _then_ invoked. This only matters in a narrow set of use cases, but
when it matters, it matters that the docs are correct.

See the issue (nodejs#5566) for a discussion on why the code has not been
modified to match the documentation, but instead the documentation has
been modified to match the code.

Fixes: nodejs/node#5566
PR-URL: nodejs/node#6371
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
gibfahn pushed a commit to ibmruntimes/node that referenced this issue May 6, 2016
Addresses nodejs#5566. The `ee.once()` function is currently documented as
invoking the listener, and then removing it when the event is
triggered. However, this is not really the case. The listener is removed
and _then_ invoked. This only matters in a narrow set of use cases, but
when it matters, it matters that the docs are correct.

See the issue (nodejs#5566) for a discussion on why the code has not been
modified to match the documentation, but instead the documentation has
been modified to match the code.

Fixes: nodejs/node#5566
PR-URL: nodejs/node#6371
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
richardlau pushed a commit to ibmruntimes/node that referenced this issue Jun 17, 2016
Addresses nodejs#5566. The `ee.once()` function is currently documented as
invoking the listener, and then removing it when the event is
triggered. However, this is not really the case. The listener is removed
and _then_ invoked. This only matters in a narrow set of use cases, but
when it matters, it matters that the docs are correct.

See the issue (nodejs#5566) for a discussion on why the code has not been
modified to match the documentation, but instead the documentation has
been modified to match the code.

Fixes: nodejs#5566
Ref: nodejs#6371
PR-URL: nodejs/node#7103
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
richardlau pushed a commit to ibmruntimes/node that referenced this issue Jun 29, 2016
Addresses nodejs#5566. The `ee.once()` function is currently documented as
invoking the listener, and then removing it when the event is
triggered. However, this is not really the case. The listener is removed
and _then_ invoked. This only matters in a narrow set of use cases, but
when it matters, it matters that the docs are correct.

See the issue (nodejs#5566) for a discussion on why the code has not been
modified to match the documentation, but instead the documentation has
been modified to match the code.

Fixes: nodejs#5566
Ref: nodejs#6371
PR-URL: nodejs/node#7103
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants