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

Don't patch core methods #35

Closed
xPaw opened this issue Dec 1, 2019 · 8 comments · Fixed by #36
Closed

Don't patch core methods #35

xPaw opened this issue Dec 1, 2019 · 8 comments · Fixed by #36

Comments

@xPaw
Copy link

xPaw commented Dec 1, 2019

It's just causing problems in unrelated code even when your dependency is not used.

sindresorhus/got#951
sindresorhus/got#941
TooTallNate/proxy-agents#88

I'm not using https-proxy-agent directly, but the mere fact it's included by web-push (which we do use) breaks our app.

@dashmug
Copy link

dashmug commented Dec 2, 2019

I have the same problem. It breaks my app even if my app does not directly use node-https-proxy-agent.

TooTallNate added a commit that referenced this issue Dec 2, 2019
Instead of patching over `https.request()` and `https.get()` manually
to add the `secureEndpoint` boolean, utilize the stack trace of the
current call logic to determine whether or not the `https.js` core
module is invoking `new ClientRequest()`.

In theory, this is still fragile logic, but should be more future-proof
and cleaner than patching over a core module, which is never really
desirable.

Fixes #29.
Closes #30.
Closes #35.
@TooTallNate
Copy link
Owner

Thanks for the heads up. Please see #36 for my proposed solution.

@ouraios
Copy link

ouraios commented Dec 3, 2019

@TooTallNate When do you think you'll be able to fix this issue ? I saw that you had a working pull request, what's missing ?

@TooTallNate
Copy link
Owner

@ouraios Nothing is missing, I was just leaving the PR open for a bit to give anyone a chance to chime in if there is a problem with the fix.

TooTallNate added a commit that referenced this issue Dec 6, 2019
* Remove `https` core module patching logic

Instead of patching over `https.request()` and `https.get()` manually
to add the `secureEndpoint` boolean, utilize the stack trace of the
current call logic to determine whether or not the `https.js` core
module is invoking `new ClientRequest()`.

In theory, this is still fragile logic, but should be more future-proof
and cleaner than patching over a core module, which is never really
desirable.

Fixes #29.
Closes #30.
Closes #35.

* Remove Node 10-specific test case

* Prettier
@dguo
Copy link

dguo commented Dec 6, 2019

@TooTallNate, thanks for the fix. Do you know when you'll be able to publish it to npm?

@ouraios
Copy link

ouraios commented Dec 9, 2019

I agree with @dguo , @TooTallNate can you do a minor version release, so every package using agent-base will automatically upgrade to this fixed version ?

@fengkx
Copy link

fengkx commented Dec 29, 2019

I think socks-proxy-agent need to upgrade the agent-base dependency too.

@hildoer
Copy link

hildoer commented Apr 24, 2020

For those of plagued by this in a rats nest of upstream dependencies that include this library with the existence of the core patch, I have simply done this in a postinstall hook. Undoubtedly it breaks something in the upstream dependencies that are dependent on a polluted HTTPS core module, but my code isn't executing that code.

find node_modules/ | grep 'agent-base/patch-core' | xargs truncate -s 0

Basically, after npm install this clears out every instance of agent-base/patch-core by any upstream dependency.

It is a hack to fix a hack, but it has us working again as all of our automated tests are passing again without losing the functionality of the upstream dependencies we actually use.

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

Successfully merging a pull request may close this issue.

7 participants