-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
allow any type for customResponseHeaders config #66689
Changes from all commits
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 |
---|---|---|
|
@@ -57,7 +57,7 @@ export const config = { | |
), | ||
schema.boolean({ defaultValue: false }) | ||
), | ||
customResponseHeaders: schema.recordOf(schema.string(), schema.string(), { | ||
customResponseHeaders: schema.recordOf(schema.string(), schema.any(), { | ||
defaultValue: {}, | ||
}), | ||
host: schema.string({ | ||
|
@@ -136,7 +136,7 @@ export class HttpConfig { | |
public socketTimeout: number; | ||
public port: number; | ||
public cors: boolean | { origin: string[] }; | ||
public customResponseHeaders: Record<string, string>; | ||
public customResponseHeaders: Record<string, string | string[]>; | ||
public maxPayload: ByteSizeValue; | ||
public basePath?: string; | ||
public rewriteBasePath: boolean; | ||
|
@@ -153,7 +153,15 @@ export class HttpConfig { | |
this.host = rawHttpConfig.host; | ||
this.port = rawHttpConfig.port; | ||
this.cors = rawHttpConfig.cors; | ||
this.customResponseHeaders = rawHttpConfig.customResponseHeaders; | ||
this.customResponseHeaders = Object.entries(rawHttpConfig.customResponseHeaders ?? {}).reduce( | ||
(headers, [key, value]) => { | ||
return { | ||
...headers, | ||
[key]: Array.isArray(value) ? value.map(e => convertHeader(e)) : convertHeader(value), | ||
}; | ||
}, | ||
{} | ||
); | ||
this.maxPayload = rawHttpConfig.maxPayload; | ||
this.name = rawHttpConfig.name; | ||
this.basePath = rawHttpConfig.basePath; | ||
|
@@ -166,3 +174,7 @@ export class HttpConfig { | |
this.xsrf = rawHttpConfig.xsrf; | ||
} | ||
} | ||
|
||
const convertHeader = (entry: any): string => { | ||
return typeof entry === 'object' ? JSON.stringify(entry) : String(entry); | ||
}; | ||
Comment on lines
+178
to
+180
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. To get exactly the previous behavior back, while keeping the headers conversion logic inside core instead of delegating it to Tell me if this can be improved. 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. Makes sense to avoid breaking the previous behavior. |
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.
Lot of tests are using partials of the config. I tried to fix them, but adding
customResponseHeaders: {}
in some was breaking snapshots or even assertions about the received config, so I choose to add this?? {}
to avoid breaking tests.