|
@@ -37,7 +37,7 @@ enum ResponseType {
|
|
Binary = 3
|
|
Binary = 3
|
|
}
|
|
}
|
|
|
|
|
|
-type Part = string | number[]
|
|
|
|
|
|
+type Part = string | Uint8Array
|
|
|
|
|
|
/** The body object to be used on POST and PUT requests. */
|
|
/** The body object to be used on POST and PUT requests. */
|
|
class Body {
|
|
class Body {
|
|
@@ -58,7 +58,14 @@ class Body {
|
|
* @return The body object ready to be used on the POST and PUT requests.
|
|
* @return The body object ready to be used on the POST and PUT requests.
|
|
*/
|
|
*/
|
|
static form(data: Record<string, Part>): Body {
|
|
static form(data: Record<string, Part>): Body {
|
|
- return new Body('Form', data)
|
|
|
|
|
|
+ const form: Record<string, string | number[]> = {}
|
|
|
|
+ for (const key in data) {
|
|
|
|
+ // eslint-disable-next-line security/detect-object-injection
|
|
|
|
+ const v = data[key]
|
|
|
|
+ // eslint-disable-next-line security/detect-object-injection
|
|
|
|
+ form[key] = typeof v === 'string' ? v : Array.from(v)
|
|
|
|
+ }
|
|
|
|
+ return new Body('Form', form)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -90,8 +97,9 @@ class Body {
|
|
*
|
|
*
|
|
* @return The body object ready to be used on the POST and PUT requests.
|
|
* @return The body object ready to be used on the POST and PUT requests.
|
|
*/
|
|
*/
|
|
- static bytes(bytes: number[]): Body {
|
|
|
|
- return new Body('Bytes', bytes)
|
|
|
|
|
|
+ static bytes(bytes: Uint8Array): Body {
|
|
|
|
+ // stringifying Uint8Array doesn't return an array of numbers, so we create one here
|
|
|
|
+ return new Body('Bytes', Array.from(bytes))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|