Skip to content

Version 0.5.0 returns "Invalid argument to getAgent" on examples #38

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

Closed
timmattison opened this issue Apr 26, 2011 · 11 comments
Closed

Comments

@timmattison
Copy link
Contributor

I'm new to http-proxy but after running the example here:

https://github.com/nodejitsu/node-http-proxy/blob/v0.5.0/examples/basic-proxy.js

With some modifications (changed path of http-proxy to work in my environment) it starts but immediately throws an exception when the first client tries to connect. Is there additional setup I need to do to get it running? I am running node v0.5.0-pre according to "node --version" and just pulled http-agent from npm today (2011, April 26th).

Here is the full exception:

http.js:1446
    throw new TypeError('Invalid argument to getAgent');
          ^
TypeError: Invalid argument to getAgent
    at Object.getAgent (http.js:1446:11)
    at _getAgent (/home/tim/local/node/lib/node/.npm/http-proxy/0.5.0/package/lib/node-http-proxy.js:48:30)
    at [object Object].proxyRequest (/home/tim/local/node/lib/node/.npm/http-proxy/0.5.0/package/lib/node-http-proxy.js:377:12)
    at Server. (/home/tim/local/node/lib/node/.npm/http-proxy/0.5.0/package/lib/node-http-proxy.js:146:13)
    at Server.emit (events.js:67:17)
    at HTTPParser.onIncoming (http.js:1109:12)
    at HTTPParser.onHeadersComplete (http.js:108:31)
    at Socket.ondata (http.js:1008:22)
    at Socket._onReadable (net.js:682:27)
    at IOWatcher.onReadable [as callback] (net.js:177:10)
@timmattison
Copy link
Contributor Author

My testing shows this example does work in version 0.3.1 but not 0.4.1, 0.4.2, or 0.5.0.

@timmattison
Copy link
Contributor Author

See #39 for potential resolution

@indexzero
Copy link
Member

I will roll this into v0.5.1. This code was a workaround for a small bug in node.js core that @mikeal fixed this here nodejs/node-v0.x-archive@2b03ba5#lib/http.js

Although this commit claims it was made in February, when I released 0.5.0 it was not in the node.js source. Rebased perhaps?

@timmattison
Copy link
Contributor Author

Uh oh, looks like the clock on my VM may be off. This could be bad...

Thanks for letting me know!

Tim

On 4/26/2011 5:20 PM, indexzero wrote:

I will roll this into v0.5.1. This code was a workaround for a small bug in node.js core that @mikeal fixed this here nodejs/node-v0.x-archive@2b03ba5#lib/http.js

Although this commit claims it was made in February, when I released 0.5.0 it was not in the node.js source. Rebased perhaps?

@mikeal
Copy link

mikeal commented Apr 26, 2011

yeah, this was just a few weeks ago, i don't know why it has that date on it.

@timmattison
Copy link
Contributor Author

Oh, I thought you meant my commit.

Mine should be:
Date: Tue Apr 26 12:27:24 2011 -0400

Not sure why that other one would have a strange date.

Tim

On 4/26/2011 5:22 PM, mikeal wrote:

yeah, this was just a few weeks ago, i don't know why it has that date on it.

@indexzero
Copy link
Member

THEN THE KILLER INTERACTIVELY REBASED THE COMMIT HISTORY

@mikeal
Copy link

mikeal commented Apr 26, 2011

i think i know what happened.
i wrote this patch for v0.4.x, but it's not forward compatible with earlier 0.4.x releases so Ryan rolled it in to master, it probably conflicted and so he rebased.

@indexzero
Copy link
Member

I figured something like that. Not a problem. I'll make sure to put >= node 0.4.7 on the requirements for node-http-proxy >= 0.5.1

@manast
Copy link

manast commented May 22, 2011

I just made a clean npm install node-http-proxy, and I am using node0.5.0pre. I get the same error, I thought this was resolved long time ago?

http.js:1455
throw new TypeError('Invalid argument to getAgent');
^
TypeError: Invalid argument to getAgent
at Object.getAgent (http.js:1455:11)
at _getAgent (/home/ubuntu/server/js/server/node_modules/http-proxy/lib/node-http-proxy.js:48:30)
at [object Object].proxyRequest (/home/ubuntu/server/js/server/node_modules/http-proxy/lib/node-http-proxy.js:410:12)
at Server. (/home/ubuntu/server/js/server/node_modules/http-proxy/lib/node-http-proxy.js:155:13)
at Server.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1119:12)
at HTTPParser.onHeadersComplete (http.js:108:31)
at Socket.ondata (http.js:1018:22)
at Socket._onReadable (net.js:684:27)
at IOWatcher.onReadable as callback

@indexzero
Copy link
Member

This seems to be something (still) going on in Node.js core. The code in questions claims that it is backwards compatible: https://github.com/joyent/node/blob/master/lib/http.js#L1427

Perhaps @ry or @mikeal could shed some light on why this is popping up again. Host is still being passed as a string in node-http-proxy (i.e. "legacy" arguments) https://github.com/nodejitsu/node-http-proxy/blob/master/lib/node-http-proxy.js#L48

I think that this may be a bug in core related to options instanceof String. This syntax doesn't seem to be the correct way to identify the type of the argument. Here's a quick sample from the REPL:

'foo' instanceof String
false
typeof 'foo' == 'string'
true

Should be a quick fix. Reasonbly sure this has nothing to do with node-http-proxy.

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

4 participants