Node-http-proxy: proxy.web callback is not being called on finish

Created on 3 Feb 2016  Â·  6Comments  Â·  Source: http-party/node-http-proxy

The documentation says one can specify a callback for proxy.web() call.
But this callback gets called only if case of an error.
It isn't called when there was no error.
https://github.com/nodejitsu/node-http-proxy/blob/302d981dd2cf06dbf751b1f64e3dfea08d0f9476/lib/http-proxy/passes/web-incoming.js#L130-L142

Most helpful comment

@pyper

I am just pointing out that is the behaviour as per the docs

And I am pointing out that behaviour is not as per the docs because "the callback API" means "call back" when it's either done or aborted.
If you aren't interested in correcting that mistake in the README and renaming that word into something more appropriate like "error handler" then I don't care.

you wouldn’t be able to do much with it

I am able to do much with it.

Anyway, I have my solution and this issue is not for helping me do something, it's for pointing out the mistake in your documentation/api-design.

The workaround for those who are interested:
https://github.com/halt-hammerzeit/webapp/blob/80f2c37596e878895eaa129dc7666133e472443f/code/common/web%20server.js#L747-L766

All 6 comments

According to the docs this is the right behaviour. They say "Errors can be listened on either using the Event Emitter API” .... "or using the callback API” and then provide an example using the proxy.web() call.

@pyper a word callback in Node.js world always means only one thing: a function that will be called when the action is finished, whose first parameter is error, if any, and the rest parameters are the results.

The current proxy.web() is clearly not a "callback API".

@halt-hammerzeit I understand that, but I am just pointing out that is the behaviour as per the docs. As well, the way node-proxy is built it is all streams. If there was a callback for when there is no error, you wouldn’t be able to do much with it since response.end() would have been called on the response object between the end-user and proxy by the time the call was complete.

@halt-hammerzeit What are you trying to do?

@pyper

I am just pointing out that is the behaviour as per the docs

And I am pointing out that behaviour is not as per the docs because "the callback API" means "call back" when it's either done or aborted.
If you aren't interested in correcting that mistake in the README and renaming that word into something more appropriate like "error handler" then I don't care.

you wouldn’t be able to do much with it

I am able to do much with it.

Anyway, I have my solution and this issue is not for helping me do something, it's for pointing out the mistake in your documentation/api-design.

The workaround for those who are interested:
https://github.com/halt-hammerzeit/webapp/blob/80f2c37596e878895eaa129dc7666133e472443f/code/common/web%20server.js#L747-L766

Cheers @halt-hammerzeit! Link was much appreciated!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

miton18 picture miton18  Â·  5Comments

martindale picture martindale  Â·  6Comments

lgzhang picture lgzhang  Â·  4Comments

guillaume-at-palo picture guillaume-at-palo  Â·  4Comments

jsmylnycky picture jsmylnycky  Â·  3Comments