summaryrefslogtreecommitdiff
path: root/js/fetch_test.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-14 17:36:34 -0800
committerGitHub <noreply@github.com>2018-11-14 17:36:34 -0800
commit3c8d2bde685d015721b1c0fd6f2a3ae54c156583 (patch)
tree0f770fccbe23bd5a410612678176b449651cd8ad /js/fetch_test.ts
parent765863e87aea725301d5f528b6de15bfa6022d46 (diff)
Support request method and headers in fetch() (#1188)
Adds a general HttpHeader flatbuffer message for serializing requests and responses.
Diffstat (limited to 'js/fetch_test.ts')
-rw-r--r--js/fetch_test.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/js/fetch_test.ts b/js/fetch_test.ts
index 0c60efb9d..8fad8da75 100644
--- a/js/fetch_test.ts
+++ b/js/fetch_test.ts
@@ -46,3 +46,34 @@ testPerm({ net: true }, async function responseClone() {
assertEqual(ab[i], ab1[i]);
}
});
+
+testPerm({ net: true }, async function fetchRequest() {
+ const addr = "127.0.0.1:4501";
+ const listener = deno.listen("tcp", addr);
+ const buf = new deno.Buffer();
+ listener.accept().then(async conn => {
+ buf.readFrom(conn);
+ await conn.write(
+ new TextEncoder().encode(
+ "HTTP/1.0 404 Not Found\r\nContent-Length: 2\r\n\r\nNF"
+ )
+ );
+ conn.close();
+ });
+ const response = await fetch(`http://${addr}/blah`, {
+ method: "POST",
+ headers: [["Hello", "World"], ["Foo", "Bar"]]
+ });
+ listener.close();
+ assertEqual(response.status, 404);
+ assertEqual(response.headers.get("Content-Length"), "2");
+
+ const actual = new TextDecoder().decode(buf.bytes());
+ const expected = [
+ "POST /blah HTTP/1.1\r\n",
+ "hello: World\r\n",
+ "foo: Bar\r\n",
+ `host: ${addr}\r\n\r\n`
+ ].join("");
+ assertEqual(actual, expected);
+});