Created
February 21, 2019 21:46
-
-
Save ipcrm/bbf845fc69391f562ba69fe4907ae3d6 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAxiosRequestConfig(config: AxiosRequestConfig): AxiosRequestConfig { | |
const tunnel = tunneling.httpsOverHttp({ | |
proxy: configurationValue<tunneling.HttpsOverHttpOptions["proxy"]>("sdm.proxy"), | |
}); | |
return { | |
...config, | |
httpsAgent: tunnel, | |
proxy: false, | |
}; | |
} | |
export class AxiosHttpClient implements HttpClient { | |
public exchange<T>(url: string, | |
options: HttpClientOptions = {}): Promise<HttpResponse<T>> { | |
const optionsToUse: HttpClientOptions = { | |
...DefaultHttpClientOptions, | |
...options, | |
}; | |
const request = () => { | |
return axios.request(this.configureOptions(configureProxy({ | |
url, | |
headers: optionsToUse.headers, | |
method: optionsToUse.method.toString().toUpperCase(), | |
data: optionsToUse.body, | |
...optionsToUse.options, | |
}))) | |
.then(result => { | |
return { | |
status: result.status, | |
headers: result.headers, | |
body: result.data, | |
}; | |
}); | |
}; | |
return doWithRetry<HttpResponse<T>>(request, `Requesting '${url}'`, optionsToUse.retry); | |
} | |
protected configureOptions(options: AxiosRequestConfig): AxiosRequestConfig { | |
if (options.url.includes("thing.com")) { | |
return createAxiosRequestConfig(options); | |
} | |
return options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment