-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
fix(ClientRequest): support the "auth" option #440
fix(ClientRequest): support the "auth" option #440
Conversation
cc62ba3
to
301b3bf
Compare
@@ -159,7 +166,10 @@ export function getUrlByRequestOptions(options: ResolvedRequestOptions): URL { | |||
: '' | |||
logger.info('auth string:', authString) | |||
|
|||
const url = new URL(`${protocol}//${authString}${hostname}${path}`) | |||
const url = new URL(`${protocol}//${hostname}${path}`) | |||
url.username = credentials?.username || '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL you can set username
and password
on the existing URL instance since href
is a getter. This makes the URL construct a bit more readable.
const password = 'secret123' | ||
const req = http.request( | ||
// The request URL can include the basic auth directly. | ||
new URL( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also added a test case for when the auth is included in the URL
itself.
This was also where I mistakingly assumed username
and password
are ClientRequest
options. They are not. They are the options of the URL
instance if you wish to create it object-first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a few minor adjustments but it looks great! Thank you for opening this, @mikicho 👏
Please let me know if this sufficiently addresses the use case. If it does, we can proceed with releasing this. |
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. |
Options: https://nodejs.org/api/http.html#httprequesturl-options-callback
@kettanaito
closes #438