summaryrefslogtreecommitdiff
path: root/cli/js/web/body.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/web/body.ts')
-rw-r--r--cli/js/web/body.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts
index f0d88be4b..9c4997755 100644
--- a/cli/js/web/body.ts
+++ b/cli/js/web/body.ts
@@ -8,15 +8,7 @@ import { getHeaderValueParams, hasHeaderValueOf } from "./util.ts";
const { TextEncoder, TextDecoder } = encoding;
const DenoBlob = blob.DenoBlob;
-export type BodySource =
- | Blob
- | BufferSource
- | FormData
- | URLSearchParams
- | ReadableStream
- | string;
-
-function validateBodyType(owner: Body, bodySource: BodySource): boolean {
+function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean {
if (
bodySource instanceof Int8Array ||
bodySource instanceof Int16Array ||
@@ -74,6 +66,8 @@ async function bufferFromStream(
parts.push(encoder.encode(value));
} else if (value instanceof ArrayBuffer) {
parts.push(new Uint8Array(value));
+ } else if (value instanceof Uint8Array) {
+ parts.push(value);
} else if (!value) {
// noop for undefined
} else {
@@ -90,7 +84,10 @@ export const BodyUsedError =
export class Body implements domTypes.Body {
protected _stream: ReadableStreamImpl<string | ArrayBuffer> | null;
- constructor(protected _bodySource: BodySource, readonly contentType: string) {
+ constructor(
+ protected _bodySource: BodyInit | null,
+ readonly contentType: string
+ ) {
validateBodyType(this, _bodySource);
this._bodySource = _bodySource;
this.contentType = contentType;
@@ -126,7 +123,9 @@ export class Body implements domTypes.Body {
}
public async blob(): Promise<Blob> {
- return new DenoBlob([await this.arrayBuffer()]);
+ return new DenoBlob([await this.arrayBuffer()], {
+ type: this.contentType,
+ });
}
// ref: https://fetch.spec.whatwg.org/#body-mixin