-
-
Notifications
You must be signed in to change notification settings - Fork 375
Fix how headers are handled in @hey-api/client-angular #3860
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
97d5e10
8db4b2d
2704bcc
6e48019
144be7d
fb09d02
eb9cdc4
791f92e
219c1ee
4c5d311
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,14 +85,18 @@ export const createClient = (config: Config = {}): Client => { | |
| opts.headers.delete('Content-Type'); | ||
| } | ||
|
|
||
| return opts; | ||
| }; | ||
|
|
||
| const finalizeRequest = (opts: any) => { | ||
| const url = buildUrl(opts as Config & RequestOptions); | ||
|
|
||
| const req = new HttpRequest<unknown>(opts.method ?? 'GET', url, getValidRequestBody(opts), { | ||
| redirect: 'follow', | ||
| ...opts, | ||
| }); | ||
|
|
||
| return { opts, req, url }; | ||
| return { req, url }; | ||
| }; | ||
|
|
||
| const beforeRequest = async < | ||
|
|
@@ -103,10 +107,10 @@ export const createClient = (config: Config = {}): Client => { | |
| >( | ||
| options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>, | ||
| ) => { | ||
| const { opts, req, url } = requestOptions(options); | ||
| const opts = requestOptions(options); | ||
|
|
||
| if (opts.security) { | ||
| await setAuthParams({ | ||
| opts.headers = await setAuthParams({ | ||
| ...opts, | ||
| security: opts.security, | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Query-auth tokens still get dropped here. |
||
|
|
@@ -116,6 +120,8 @@ export const createClient = (config: Config = {}): Client => { | |
| await opts.requestValidator(opts); | ||
| } | ||
|
|
||
| const { req, url } = finalizeRequest(opts); | ||
|
|
||
| return { opts, req, url }; | ||
| }; | ||
|
|
||
|
|
@@ -237,7 +243,7 @@ export const createClient = (config: Config = {}): Client => { | |
| throw new Error('Request validation is not supported in requestOptions'); | ||
| } | ||
|
|
||
| return requestOptions(options).req; | ||
| return finalizeRequest(requestOptions(options)).req; | ||
| }, | ||
| setConfig, | ||
| sse: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,8 +211,9 @@ export const setAuthParams = async ( | |
| break; | ||
| } | ||
|
|
||
| return; | ||
| return options.headers; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing, but worth confirming intent:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, you're right. I don't think that should be there |
||
| } | ||
| return options.headers; | ||
| }; | ||
|
|
||
| export const buildUrl: Client['buildUrl'] = (options) => { | ||
|
|
||
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.
opts: anyweakens the type safety that the previous inline construction had —optsis the inferred return ofrequestOptionsand the rest of the file (e.g. line 92's castopts as Config & RequestOptions) implicitly relies on that. Consider(opts: ReturnType<typeof requestOptions>)so the cast is the only erasure.