Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Spencer <email@spalger.com> Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
parent
01d2ba4e12
commit
02b138b2f3
2 changed files with 13 additions and 3 deletions
|
@ -115,6 +115,7 @@ export class KbnClientImportExport {
|
|||
excludeExportDetails: true,
|
||||
includeReferencesDeep: true,
|
||||
},
|
||||
responseType: 'text',
|
||||
});
|
||||
|
||||
if (typeof resp.data !== 'string') {
|
||||
|
|
|
@ -10,7 +10,7 @@ import Url from 'url';
|
|||
import Https from 'https';
|
||||
import Qs from 'querystring';
|
||||
|
||||
import Axios, { AxiosResponse } from 'axios';
|
||||
import Axios, { AxiosResponse, ResponseType } from 'axios';
|
||||
import { ToolingLog, isAxiosRequestError, isAxiosResponseError } from '@kbn/dev-utils';
|
||||
|
||||
const isConcliftOnGetError = (error: any) => {
|
||||
|
@ -53,6 +53,7 @@ export interface ReqOptions {
|
|||
body?: any;
|
||||
retries?: number;
|
||||
headers?: Record<string, string>;
|
||||
responseType?: ResponseType;
|
||||
}
|
||||
|
||||
const delay = (ms: number) =>
|
||||
|
@ -84,11 +85,16 @@ export class KbnClientRequester {
|
|||
}
|
||||
|
||||
public resolveUrl(relativeUrl: string = '/') {
|
||||
return Url.resolve(this.pickUrl(), relativeUrl);
|
||||
let baseUrl = this.pickUrl();
|
||||
if (!baseUrl.endsWith('/')) {
|
||||
baseUrl += '/';
|
||||
}
|
||||
const relative = relativeUrl.startsWith('/') ? relativeUrl.slice(1) : relativeUrl;
|
||||
return Url.resolve(baseUrl, relative);
|
||||
}
|
||||
|
||||
async request<T>(options: ReqOptions): Promise<AxiosResponse<T>> {
|
||||
const url = Url.resolve(this.pickUrl(), options.path);
|
||||
const url = this.resolveUrl(options.path);
|
||||
const description = options.description || `${options.method} ${url}`;
|
||||
let attempt = 0;
|
||||
const maxAttempts = options.retries ?? DEFAULT_MAX_ATTEMPTS;
|
||||
|
@ -107,6 +113,9 @@ export class KbnClientRequester {
|
|||
'kbn-xsrf': 'kbn-client',
|
||||
},
|
||||
httpsAgent: this.httpsAgent,
|
||||
responseType: options.responseType,
|
||||
// work around https://github.com/axios/axios/issues/2791
|
||||
transformResponse: options.responseType === 'text' ? [(x) => x] : undefined,
|
||||
paramsSerializer: (params) => Qs.stringify(params),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue