This commit is contained in:
Salman Muin Kayser Chishti
2025-08-06 12:57:10 +01:00
parent 8c3fc9ed99
commit bcb928642f
+32 -24
View File
@@ -275,10 +275,11 @@ export class HttpClient {
Headers.Accept, Headers.Accept,
MediaTypes.ApplicationJson MediaTypes.ApplicationJson
) )
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultContentTypeHeader( additionalHeaders[Headers.ContentType] =
additionalHeaders, this._getExistingOrDefaultContentTypeHeader(
MediaTypes.ApplicationJson additionalHeaders,
) MediaTypes.ApplicationJson
)
const res: HttpClientResponse = await this.post( const res: HttpClientResponse = await this.post(
requestUrl, requestUrl,
data, data,
@@ -298,10 +299,11 @@ export class HttpClient {
Headers.Accept, Headers.Accept,
MediaTypes.ApplicationJson MediaTypes.ApplicationJson
) )
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultContentTypeHeader( additionalHeaders[Headers.ContentType] =
additionalHeaders, this._getExistingOrDefaultContentTypeHeader(
MediaTypes.ApplicationJson additionalHeaders,
) MediaTypes.ApplicationJson
)
const res: HttpClientResponse = await this.put( const res: HttpClientResponse = await this.put(
requestUrl, requestUrl,
data, data,
@@ -321,10 +323,11 @@ export class HttpClient {
Headers.Accept, Headers.Accept,
MediaTypes.ApplicationJson MediaTypes.ApplicationJson
) )
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultContentTypeHeader( additionalHeaders[Headers.ContentType] =
additionalHeaders, this._getExistingOrDefaultContentTypeHeader(
MediaTypes.ApplicationJson additionalHeaders,
) MediaTypes.ApplicationJson
)
const res: HttpClientResponse = await this.patch( const res: HttpClientResponse = await this.patch(
requestUrl, requestUrl,
data, data,
@@ -634,30 +637,35 @@ export class HttpClient {
if (this.requestOptions && this.requestOptions.headers) { if (this.requestOptions && this.requestOptions.headers) {
const headerValue = lowercaseKeys(this.requestOptions.headers)[header] const headerValue = lowercaseKeys(this.requestOptions.headers)[header]
if (headerValue) { if (headerValue) {
clientHeader = typeof headerValue === 'number' ? headerValue.toString() : headerValue clientHeader =
typeof headerValue === 'number' ? headerValue.toString() : headerValue
} }
} }
const additionalValue = additionalHeaders[header] const additionalValue = additionalHeaders[header]
if (additionalValue !== undefined) { if (additionalValue !== undefined) {
return typeof additionalValue === 'number' ? additionalValue.toString() : additionalValue return typeof additionalValue === 'number'
? additionalValue.toString()
: additionalValue
} }
if (clientHeader !== undefined) { if (clientHeader !== undefined) {
return clientHeader return clientHeader
} }
return _default return _default
} }
private _getExistingOrDefaultContentTypeHeader( private _getExistingOrDefaultContentTypeHeader(
additionalHeaders: http.OutgoingHttpHeaders, additionalHeaders: http.OutgoingHttpHeaders,
_default: string _default: string
): string { ): string {
let clientHeader: string | undefined let clientHeader: string | undefined
if (this.requestOptions && this.requestOptions.headers) { if (this.requestOptions && this.requestOptions.headers) {
const headerValue = lowercaseKeys(this.requestOptions.headers)[Headers.ContentType] const headerValue = lowercaseKeys(this.requestOptions.headers)[
Headers.ContentType
]
if (headerValue) { if (headerValue) {
if (typeof headerValue === 'number') { if (typeof headerValue === 'number') {
clientHeader = String(headerValue) clientHeader = String(headerValue)
@@ -668,9 +676,9 @@ export class HttpClient {
} }
} }
} }
const additionalValue = additionalHeaders[Headers.ContentType] const additionalValue = additionalHeaders[Headers.ContentType]
// Return the first non-undefined value, converting numbers or arrays to strings if necessary // Return the first non-undefined value, converting numbers or arrays to strings if necessary
if (additionalValue !== undefined) { if (additionalValue !== undefined) {
if (typeof additionalValue === 'number') { if (typeof additionalValue === 'number') {
@@ -681,11 +689,11 @@ export class HttpClient {
return additionalValue return additionalValue
} }
} }
if (clientHeader !== undefined) { if (clientHeader !== undefined) {
return clientHeader return clientHeader
} }
return _default return _default
} }