Skip to content

Instantly share code, notes, and snippets.

@ipcrm
Created February 21, 2019 21:46
Show Gist options
  • Save ipcrm/bbf845fc69391f562ba69fe4907ae3d6 to your computer and use it in GitHub Desktop.
Save ipcrm/bbf845fc69391f562ba69fe4907ae3d6 to your computer and use it in GitHub Desktop.
test
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