[kbnClient] fix basePath handling and export reponse type (#97277)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
347882f01a
commit
9987e3d73b
|
@ -115,6 +115,7 @@ export class KbnClientImportExport {
|
||||||
excludeExportDetails: true,
|
excludeExportDetails: true,
|
||||||
includeReferencesDeep: true,
|
includeReferencesDeep: true,
|
||||||
},
|
},
|
||||||
|
responseType: 'text',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof resp.data !== 'string') {
|
if (typeof resp.data !== 'string') {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import Url from 'url';
|
||||||
import Https from 'https';
|
import Https from 'https';
|
||||||
import Qs from 'querystring';
|
import Qs from 'querystring';
|
||||||
|
|
||||||
import Axios, { AxiosResponse } from 'axios';
|
import Axios, { AxiosResponse, ResponseType } from 'axios';
|
||||||
import { ToolingLog, isAxiosRequestError, isAxiosResponseError } from '@kbn/dev-utils';
|
import { ToolingLog, isAxiosRequestError, isAxiosResponseError } from '@kbn/dev-utils';
|
||||||
|
|
||||||
const isConcliftOnGetError = (error: any) => {
|
const isConcliftOnGetError = (error: any) => {
|
||||||
|
@ -53,6 +53,7 @@ export interface ReqOptions {
|
||||||
body?: any;
|
body?: any;
|
||||||
retries?: number;
|
retries?: number;
|
||||||
headers?: Record<string, string>;
|
headers?: Record<string, string>;
|
||||||
|
responseType?: ResponseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const delay = (ms: number) =>
|
const delay = (ms: number) =>
|
||||||
|
@ -84,11 +85,16 @@ export class KbnClientRequester {
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveUrl(relativeUrl: string = '/') {
|
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>> {
|
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}`;
|
const description = options.description || `${options.method} ${url}`;
|
||||||
let attempt = 0;
|
let attempt = 0;
|
||||||
const maxAttempts = options.retries ?? DEFAULT_MAX_ATTEMPTS;
|
const maxAttempts = options.retries ?? DEFAULT_MAX_ATTEMPTS;
|
||||||
|
@ -107,6 +113,9 @@ export class KbnClientRequester {
|
||||||
'kbn-xsrf': 'kbn-client',
|
'kbn-xsrf': 'kbn-client',
|
||||||
},
|
},
|
||||||
httpsAgent: this.httpsAgent,
|
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),
|
paramsSerializer: (params) => Qs.stringify(params),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue