diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-11-14 21:19:38 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-11-16 11:44:25 +0800 |
commit | eaec5a878007324cf996edc39ecf3339bfd23e7a (patch) | |
tree | 392edbdcf4ffd49ca0163ecec3bc47a240eafba5 /js/fetch.ts | |
parent | 975f75d81ea4b41b634f2c5f167082904ed7f368 (diff) |
Support uploading data from fetch()
Does not yet support streaming, only strings and TypedArrays for now.
Diffstat (limited to 'js/fetch.ts')
-rw-r--r-- | js/fetch.ts | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/js/fetch.ts b/js/fetch.ts index 636bbba10..06ed5dbca 100644 --- a/js/fetch.ts +++ b/js/fetch.ts @@ -1,5 +1,5 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. -import { assert, createResolvable, notImplemented } from "./util"; +import { assert, createResolvable, notImplemented, isTypedArray } from "./util"; import * as flatbuffers from "./flatbuffers"; import { sendAsync } from "./dispatch"; import * as msg from "gen/msg_generated"; @@ -204,6 +204,7 @@ export async function fetch( let url: string; let method: string | null = null; let headers: domTypes.Headers | null = null; + let body: ArrayBufferView | undefined; if (typeof input === "string") { url = input; @@ -217,6 +218,16 @@ export async function fetch( } else { headers = null; } + + if (init.body) { + if (typeof init.body === "string") { + body = new TextEncoder().encode(init.body); + } else if (isTypedArray(init.body)) { + body = init.body; + } else { + notImplemented(); + } + } } } else { url = input.url; @@ -232,7 +243,8 @@ export async function fetch( const resBase = await sendAsync( builder, msg.Any.Fetch, - msg.Fetch.endFetch(builder) + msg.Fetch.endFetch(builder), + body ); // Decode FetchRes |