diff --git a/lib/progress.ts b/lib/progress.ts index 0e1afd1..3fee9d6 100644 --- a/lib/progress.ts +++ b/lib/progress.ts @@ -93,16 +93,12 @@ export interface BalenaRequestPassThroughStream extends Stream.PassThrough { * console.log(state) */ export function estimate( - requestAsync?: ReturnType, + requestAsync: ReturnType = utils.getRequestAsync(), isBrowser?: boolean, ) { return async function ( options: BalenaRequestOptions, ): Promise { - if (requestAsync == null) { - requestAsync = utils.getRequestAsync(); - } - options.gzip = false; options.headers!['Accept-Encoding'] = 'gzip, deflate'; diff --git a/lib/utils.ts b/lib/utils.ts index 781c395..c6c042e 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -262,11 +262,9 @@ const processRequestOptions = function (options: BalenaRequestOptions) { url += (url.indexOf('?') >= 0 ? '&' : '?') + params; } - let { body, headers } = options; - if (headers == null) { - headers = {} as Record; - } - if (options.json && body) { + let { body } = options; + const { headers = {}, json } = options; + if (json && body) { body = JSON.stringify(body); headers['Content-Type'] = 'application/json'; }