Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No abort() method on invalid protocol #1588

Closed
Mickael-van-der-Beek opened this issue May 19, 2015 · 2 comments
Closed

No abort() method on invalid protocol #1588

Mickael-van-der-Beek opened this issue May 19, 2015 · 2 comments

Comments

@Mickael-van-der-Beek
Copy link

If you are redirected to a site with an invalid protocol, request will handle this fine and emits an error event with the message:

[Error: Invalid protocol: mailto:]

Now if you want to handle that error and abort the request like this:

var request = require('request');

var requestStream = request('http://httpbin.org/redirect-to?url=mailto:test@example.com');

requestStream
    .on('error', function () {
        console.log('[error]', arguments);
        requestStream.abort();
    });

you will get the following exception:

/node_modules/request/request.js:1264
    self.response.abort()
                  ^
TypeError: Object #<IncomingMessage> has no method 'abort'
    at Request.abort (/node_modules/request/request.js:1264:19)
    at Request.<anonymous> (/protocol-issue.js:12:17)
    at Request.emit (events.js:95:17)
    at Request.init (/node_modules/request/request.js:591:17)
    at Request.onRequestResponse (/node_modules/request/request.js:1127:10)
    at ClientRequest.emit (events.js:95:17)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1688:21)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
    at Socket.socketOnData [as ondata] (http.js:1583:20)
    at TCP.onread (net.js:527:27)

due to the IncomingMessage object not having a abort() method.

I'm calling the abort() method here just to make sure that everything is cleaned-up after the request errored-out (no memory leaks).

@pierreliefauche
Copy link

I ran into this exception too, not even calling abort() on Request.

TypeError: self.response.abort is not a function
    at Request.abort (/app/node_modules/request/request.js:1047:19)
    at Request.init (/app/node_modules/request/request.js:285:10)
    at Redirect.onResponse (/app/node_modules/request/lib/redirect.js:148:11)
    at Request.onRequestResponse (/app/node_modules/request/request.js:897:22)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.
    at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
    at Socket.socketOnData (_http_client.js:311:20)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)

Why would abort() be called on an IncomingMessage btw?
Was it meant to be destroy()?

@simov
Copy link
Member

simov commented Dec 10, 2015

Why would abort() be called on an IncomingMessage btw?
Was it meant to be destroy()?

Yep, I think so, it should be fixed here #1958

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants