summaryrefslogtreecommitdiff
path: root/http_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2018-12-17 17:49:10 +0100
committerRyan Dahl <ry@tinyclouds.org>2018-12-17 11:49:10 -0500
commitf6dae45cd2bb0615c136188b4dba8a3272ac5d70 (patch)
tree9330a72a0c9eda2f668d00f07a7c6b11d2edd346 /http_test.ts
parent579b92de599b056c308a3b2d26f0b09188c4441b (diff)
First pass at streaming http response (denoland/deno_std#16)
Original: https://github.com/denoland/deno_std/commit/269665873a9219423085418d605b8af8ac2565dc
Diffstat (limited to 'http_test.ts')
-rw-r--r--http_test.ts58
1 files changed, 58 insertions, 0 deletions
diff --git a/http_test.ts b/http_test.ts
new file mode 100644
index 000000000..879afbf53
--- /dev/null
+++ b/http_test.ts
@@ -0,0 +1,58 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Ported from
+// https://github.com/golang/go/blob/master/src/net/http/responsewrite_test.go
+
+import {
+ test,
+ assert,
+ assertEqual
+} from "https://deno.land/x/testing/testing.ts";
+
+import {
+ listenAndServe,
+ ServerRequest,
+ setContentLength,
+ Response
+} from "./http";
+import { Buffer } from "./buffer";
+import { BufWriter } from "./bufio";
+
+interface ResponseTest {
+ response: Response;
+ raw: string;
+}
+
+const responseTests: ResponseTest[] = [
+ // Default response
+ {
+ response: {},
+ raw: "HTTP/1.1 200 OK\r\n" + "\r\n"
+ },
+ // HTTP/1.1, chunked coding; empty trailer; close
+ {
+ response: {
+ status: 200,
+ body: new Buffer(new TextEncoder().encode("abcdef"))
+ },
+
+ raw:
+ "HTTP/1.1 200 OK\r\n" +
+ "transfer-encoding: chunked\r\n\r\n" +
+ "6\r\nabcdef\r\n0\r\n\r\n"
+ }
+];
+
+test(async function responseWrite() {
+ for (const testCase of responseTests) {
+ const buf = new Buffer();
+ const bufw = new BufWriter(buf);
+ const request = new ServerRequest();
+ request.w = bufw;
+
+ await request.respond(testCase.response);
+ assertEqual(buf.toString(), testCase.raw);
+ }
+});