-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Support "CONNECT" requests (in proxies) #481
Comments
Hey, @jcarlsonautomatiq. Thanks for reporting this. Not sure what's going off here. The We need to add a test for this. |
@jcarlsonautomatiq can you please share how you intend to mock those requests? |
Your original example also has a mistake: TypeScript:
Runtime:
I can help with fixing this but I need an exact example that is complete and working (well, failing, in our case). |
This code is currently being migrated from raw working but untested JS to Typescript which was one of the reasons I was actually adding the unit tests. I wonder if there is an update in got as well we are on "got-cjs": "^12.0.1" and it doesn't cause a protocol error. I will see about stripping this down to remove all the company stuff. As for testing it I was hoping I would be able to intercept the proxy url and then look at the original request to determine what to return (or just grab a ?url out of the call). A little hacky but it would let me use the proxy calls and ensure I didn't break anything in the migration. I will hack up a proper working snippet this morning. |
The issue with the path originates from here: I'm not sure what's the intention here by providing the following request options to create a request: [
{
method: 'CONNECT',
host: 'fake.proxy',
port: '443',
path: 'fake.ping:80',
setHost: false,
headers: {
connection: 'keep-alive',
host: 'fake.ping:80',
'proxy-authorization': 'Basic cHJveHlVc2VybmFtZTpwcm94eVBhc3N3b3Jk'
},
agent: false,
timeout: 0
}
] What's the intended end request URL here, I wonder? I can assume it's
And this one is far more interesting. See, the Fetch API specification forbids creating requests with new Request('/resource', { method: 'CONNECT' }) This fails standalone. |
The code is using some long lived proxies from Nimble. I expect that might be some of the strange connection issue but that is definitely odd. And apologies I should have had the fully working example in place initially.
|
It seems like if the invalid URL error is fixed this code test will probably have to be moved to the browser version of the MSW lib and only tested e2e which should be fine. Plus eventually I will run into the same agent and type conflicts :) I will look more at the hpagent code that it might need a note about not being used in Node directly. Or forcing a custom http agent when used with a keepAlive connection outside a browser. odd ad of Nodejs > 19 supposedly keepAlive works with native fetch but finding definitive info about CONNECT in the spec is surprisingly hard. https://stackoverflow.com/questions/62500011/reuse-tcp-connection-with-node-fetch-in-node-js |
Okay, so learned a lot from the Node.js docs, Got, and The URL is invalid, or is it?Turns out, when performing the const options = {
port: 1337,
host: '127.0.0.1',
method: 'CONNECT',
path: 'www.google.com:80',
}
const req = http.request(options)
Moreover, when the server receives that request, the Request flow during proxyingThis is what happens to the request in a simplified proxy setup (following the same Node.js example):
In the I assume that last part is handled by |
Basically, we don't support this message exchange right now. This is a new feature request and I will prioritize it accordingly. Will push the WIP pull request I have right now with the failing test and some findings. Thanks for making this apparent, @jcarlsonautomatiq! I'm not sure as of now how to properly support this. Since the |
Thanks for putting all the information in here it makes it a lot easier to think it through! If I might recommend a possible test framework solution I think just about everyone would accept it might go like this (I certainly would):
|
MSW is a great library and I have used it successfully in other "got" calls but in one part of my unit testing I was actually checking that a proxy call would actually try and use the proxy. Unfortunately I think the way that the path and proxy information is generated results in an invalid URL which bails before you can get a matcher to handle it. The proxy host is correctly assigned but then the path(the actual url we call) is just directly concatenated as a path.
Code that pretty much reproduces it.
The text was updated successfully, but these errors were encountered: