-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
this._getSession is not a function while use HttpsProxyAgent #675
Comments
Seeing this as well, with 0.37.1 and Node v20.12.0. My use case is MSW running in a Vitest test, and trying to access (unmocked) HTTPS endpoints. I think the code in the Node repo is here: https://github.com/nodejs/node/blob/v20.x/lib/https.js#L163 Possibly a situation in the way that the |
interceptors/src/interceptors/ClientRequest/agents.ts Lines 67 to 82 in c338da8
Looks like what happens is that Given that I'm not sure of the intent here. Hopefully somebody who knows better what's intended to happen here, might just be @kettanaito |
@sebws do you mean something like: public createConnection(options: any, callback: any) {
const createConnection =
this.customAgent.createConnection ||
super.createConnection |
I think I may have, but as far as I remember it might not have been so simple |
I think we should let users use whatever agent they want: public createConnection(options: any, callback: any): net.Socket {
- const createConnection =
- this.customAgent instanceof https.Agent
- ? this.customAgent.createConnection
- : super.createConnection
+ let _createConnection = super.createConnection
+ let _options = options
- const createConnectionOptions =
- this.customAgent instanceof https.Agent
- ? {
- ...options,
- ...this.customAgent.options,
- }
- : options
+ if (typeof this.customAgent !== 'boolean' && this.customAgent?.createConnection) {
+ _createConnection = this.customAgent.createConnection
+ _options = { ...options, ...this.customAgent.options }
+ }
const socket = new MockHttpSocket({
connectionOptions: options,
- createConnection: createConnection.bind(
+ createConnection: _createConnection.bind(
this.customAgent || this,
- createConnectionOptions,
+ _options,
callback
),
onRequest: this.onRequest.bind(this), @kettanaito WDYT? |
I don't remember, is there a reason it's not as simple as doing the instanceof check in the .bind call as well? It seems at least like a starting point. Some very quick testing to me seems to show it fixing the example repo for me |
Could you provide a code example to clarify your point? |
public createConnection(options: any, callback: any) {
const createConnection =
(this.customAgent instanceof https.Agent &&
this.customAgent.createConnection) ||
super.createConnection
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
(this.customAgent instanceof https.Agent && this.customAgent) || this,
options,
callback
),
onRequest: this.onRequest.bind(this),
onResponse: this.onResponse.bind(this),
})
return socket
} The condition could be reused but just to demonstrate where there's a difference between the conditions possibly causing an issue |
Hi, I encounter a bug when I use proxy for requests
Example repo https://github.com/WhoisUnknown/example-interseptor
I used version 0.36.10
The text was updated successfully, but these errors were encountered: