Got: tunnel compatability for proxying broken in Version 10

Created on 27 Dec 2019  路  8Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: Tested in 10.11.0 and 13.5.0
  • OS & version: Windows 10 1903

Proxying requests via the tunnel module as reccomended in the readme fail using got 10.

Actual behavior

An error is thrown:

tunnel.js:208    var hostHeader = options.request.getHeader('host');
                                     ^
TypeError: options.request.getHeader is not a function    at ...\node_modules\tunnel\lib\tunnel.js:208:38    at ClientRequest.onConnect (...\node_modules\tunnel\lib\tunnel.js:172:12)

I recognize that the error is thrown within tunnel code and not got, but as the README reccomends to use tunnel with example code provided, I think this behavior is worth opening an issue about.

Expected behavior

No error is thrown, as occurs using got 9.6.0

Code to reproduce

Replace the proxy options with a working proxy (I have tested using both Charles proxy and live proxies)

const got = require('got');
const tunnel = require('tunnel');

got('https://sindresorhus.com', {
    agent: tunnel.httpsOverHttp({
        proxy: {
            host: 'localhost',
            port: "8888"
        }
    })
});

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.
bug

All 8 comments

I have the same issue.

Temporary solution that I have created for myself

let https = require('https');
gotOptions.request = https.request;
gotOptions.hooks = {
    beforeRequest: [
        options => {
            options.request.getHeader = (name) => options.headers[name] || null;;
        }
    ]
};

Also have problems with this code

got('https://v4.icanhazip.com/', {
  agent: tunnel.httpsOverHttp({ proxy: { ... }),
  timeout: 5000
})

Error:

project/node_modules/tunnel/lib/tunnel.js:183
    options.request.emit('error', error);
                    ^
TypeError: options.request.emit is not a function
    at ClientRequest.onError (/project/node_modules/tunnel/lib/tunnel.js:183:21)
    at Object.onceWrapper (events.js:412:26)
    at ClientRequest.emit (events.js:305:20)
    at ClientRequest.EventEmitter.emit (domain.js:483:12)
    at Socket.socketErrorListener (_http_client.js:423:9)
    at Socket.emit (events.js:305:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at emitErrorNT (internal/streams/destroy.js:84:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Is there any ETA for the release of this fix?

test several packages,
tunnel, https-proxy-agent, proxy-agent and so on...

this's the only work one
https://github.com/zjael/simple-proxy-agent

and much faster, about 3 times against before. (v9.x with tunnel)

@szmarczak
I noticed that when accessing https using above one with a Local Proxy
it doesn't work, just hang up, I think maybe its because got distinguish http/https strictly, but anyway, the protocol of 'Agent' is not so clear.

For comparison purposes, I tried needle, it works well.
plz make a test if you have time.

besides, when I try to GET this url
using same proxy node, same headers, the got trigger 503 error high probability. 90% maybe,(for both v9.x v10.x)
but needle works well almost every time, so wired.
are there some "internal marks" of Got, could be detected by the Oracle's anti-robo system?

test several packages,
tunnel, https-proxy-agent, proxy-agent and so on...

this's the only work one
https://github.com/zjael/simple-proxy-agent

https-proxy-agent works fine for me

test several packages,
tunnel, https-proxy-agent, proxy-agent and so on...
this's the only work one
https://github.com/zjael/simple-proxy-agent

https-proxy-agent works fine for me

Not work for me as described above,
503 error,
but needle works well, so weird

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alanzhaonys picture alanzhaonys  路  4Comments

jamestalmage picture jamestalmage  路  3Comments

quocnguyen picture quocnguyen  路  4Comments

lukechu10 picture lukechu10  路  3Comments

dominusmars picture dominusmars  路  3Comments