summaryrefslogtreecommitdiff
path: root/std/http/racing_server_test.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-02-25 12:49:39 +0900
committerGitHub <noreply@github.com>2020-02-24 22:49:39 -0500
commit22f88b9f37b7e233fd4f15b73d5a2096224e56dc (patch)
treea623c34e8af0e98ed8d56d875412688cab79634b /std/http/racing_server_test.ts
parent5c1ab080cd8989c3ac2b3a8c919fe14052feac79 (diff)
fix: [http] Consume unread body and trailers before reading next request (#3990)
- Added `ServerRequest.finalize()`: consuming all unread body stream and trailers. - This is cleanup method for reading next request from same keep-alive connection. - Needed when handler didn't consume all body and trailers even after responding. - refactor: `ServerRequest._bodyStream()`, `ServerRequestBody` are removed. - Now using `bodyReader()` and `chunkedBodyReader()` instead. - fix: Trailers should only be read `transfer-encoding` is `chunked` and `trailer` header is set and its value is valid. - fix: use `Headers.append()` on reading trailers. - fix: delete `trailer` field from headers after reading trailers. - reorg: Several functions related to IO are moved into `http/io.ts`
Diffstat (limited to 'std/http/racing_server_test.ts')
-rw-r--r--std/http/racing_server_test.ts44
1 files changed, 29 insertions, 15 deletions
diff --git a/std/http/racing_server_test.ts b/std/http/racing_server_test.ts
index 639935339..07df92bae 100644
--- a/std/http/racing_server_test.ts
+++ b/std/http/racing_server_test.ts
@@ -1,7 +1,7 @@
const { connect, run } = Deno;
import { assert, assertEquals } from "../testing/asserts.ts";
-import { BufReader } from "../io/bufio.ts";
+import { BufReader, BufWriter } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
let server: Deno.Process;
@@ -21,20 +21,20 @@ function killServer(): void {
server.stdout?.close();
}
-const input = `GET / HTTP/1.1
-
-GET / HTTP/1.1
-
-GET / HTTP/1.1
-
-GET / HTTP/1.1
-
-`;
+const input = [
+ "GET / HTTP/1.1\r\n\r\n",
+ "GET / HTTP/1.1\r\n\r\n",
+ "GET / HTTP/1.1\r\n\r\n",
+ "POST / HTTP/1.1\r\ncontent-length: 4\r\n\r\ndeno",
+ "POST / HTTP/1.1\r\ntransfer-encoding: chunked\r\n\r\n4\r\ndeno\r\n0\r\n\r\n",
+ "POST / HTTP/1.1\r\ntransfer-encoding: chunked\r\ntrailer: deno\r\n\r\n4\r\ndeno\r\n0\r\n\r\ndeno: land\r\n\r\n",
+ "GET / HTTP/1.1\r\n\r\n"
+].join("");
const HUGE_BODY_SIZE = 1024 * 1024;
const output = `HTTP/1.1 200 OK
-content-length: 8
+content-length: 6
-Hello 1
+Step1
HTTP/1.1 200 OK
content-length: ${HUGE_BODY_SIZE}
@@ -42,9 +42,21 @@ ${"a".repeat(HUGE_BODY_SIZE)}HTTP/1.1 200 OK
content-length: ${HUGE_BODY_SIZE}
${"b".repeat(HUGE_BODY_SIZE)}HTTP/1.1 200 OK
-content-length: 8
+content-length: 6
+
+Step4
+HTTP/1.1 200 OK
+content-length: 6
+
+Step5
+HTTP/1.1 200 OK
+content-length: 6
+
+Step6
+HTTP/1.1 200 OK
+content-length: 6
-World 4
+Step7
`;
Deno.test(async function serverPipelineRace(): Promise<void> {
@@ -52,7 +64,9 @@ Deno.test(async function serverPipelineRace(): Promise<void> {
const conn = await connect({ port: 4501 });
const r = new TextProtoReader(new BufReader(conn));
- await conn.write(new TextEncoder().encode(input));
+ const w = new BufWriter(conn);
+ await w.write(new TextEncoder().encode(input));
+ await w.flush();
const outLines = output.split("\n");
// length - 1 to disregard last empty line
for (let i = 0; i < outLines.length - 1; i++) {