Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Don't redefine lowercaseKeys #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export enum MediaTypes {
ApplicationJson = 'application/json'
}

interface StrObject {
[key: string]: any
}

function lowercaseKeys(obj: StrObject) {
return Object.keys(obj).reduce(
(c: StrObject, k) => ((c[k.toLowerCase()] = obj[k]), c),
{}
)
}

/**
* Returns the proxy URL, depending upon the supplied url and proxy environment variables.
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
Expand Down Expand Up @@ -558,9 +569,6 @@ export class HttpClient {
}

private _mergeHeaders(headers: ifm.IHeaders): ifm.IHeaders {
const lowercaseKeys = obj =>
Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {})

if (this.requestOptions && this.requestOptions.headers) {
return Object.assign(
{},
Expand All @@ -577,9 +585,6 @@ export class HttpClient {
header: string,
_default: string
) {
const lowercaseKeys = obj =>
Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {})

let clientHeader: string
if (this.requestOptions && this.requestOptions.headers) {
clientHeader = lowercaseKeys(this.requestOptions.headers)[header]
Expand Down