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 username:password in NodeClientRequest #438
Comments
Hi, @mikicho. Thanks for proposing this. Can you please tell me more about the expected behavior here? Do you wish to see the username/password represented as the
You must be referring to some third-party request module. http.request({
method: 'POST',
host: 'localhost',
port: 12345,
username: 'john',
password: 'supersecret123'
}) |
I think this is a bug: const { ClientRequestInterceptor } = require('@mswjs/interceptors/ClientRequest')
const http = require('http')
const interceptor = new ClientRequestInterceptor({
name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('request', async ({request, a}) => {
await new Promise(r => setTimeout(r, 700));
throw new Error('error')
});
const req = http.request(
{
host: 'example.test',
path: '/wrong-path',
auth: 'user:pass'
},
)
req.end() // TypeError: Request cannot be constructed from a URL that includes credentials: http://user:pass@example.test/wrong-path
Probably yes.
It's one of the |
Oh, I've overlooked that one 🤦 Thanks for pointing out. I wonder why this errors. |
I see. So we need to omit the credentials from the URL itself and instead represent them in the
If you have time, I'd be thankful if you opened a pull request and we iterated on this together. Starting with some integration test would also be a good point. |
on it |
Released: v0.25.4 🎉This has been released in v0.25.4! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
The request fails when we send
auth
option tohttp.request
:logs
I think we should add some logic into the
createRequest
functionhttps://github.com/mswjs/interceptors/blob/main/src/interceptors/ClientRequest/NodeClientRequest.ts#L141
I think I can open a PR if you think I'm correct and we should fix the
createRequest
functionThe text was updated successfully, but these errors were encountered: