summaryrefslogtreecommitdiff
path: root/http/server_test.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-05-25 18:22:30 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-05-25 19:22:30 +0300
commit8d94f70bef6e44d0a0ddb6f8410a35d95a34139a (patch)
treeaf287e4f56702df99cf5fee9c6933f9117b406f7 /http/server_test.ts
parent74498f1e0c586eaa9b81809a2fedd22038d3e53d (diff)
http: add ParseHTTPVersion (denoland/deno_std#452)
Original: https://github.com/denoland/deno_std/commit/438178541e4d713c441daec7c783c745244d4d14
Diffstat (limited to 'http/server_test.ts')
-rw-r--r--http/server_test.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/http/server_test.ts b/http/server_test.ts
index 705fea1ba..fbab0234f 100644
--- a/http/server_test.ts
+++ b/http/server_test.ts
@@ -12,7 +12,8 @@ import {
Response,
ServerRequest,
writeResponse,
- readRequest
+ readRequest,
+ parseHTTPVersion
} from "./server.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { StringReader } from "../io/readers.ts";
@@ -386,4 +387,29 @@ test(async function testReadRequestError(): Promise<void> {
}
}
});
+
+// Ported from https://github.com/golang/go/blob/f5c43b9/src/net/http/request_test.go#L535-L565
+test({
+ name: "[http] parseHttpVersion",
+ fn(): void {
+ const testCases = [
+ { in: "HTTP/0.9", want: [0, 9, true] },
+ { in: "HTTP/1.0", want: [1, 0, true] },
+ { in: "HTTP/1.1", want: [1, 1, true] },
+ { in: "HTTP/3.14", want: [3, 14, true] },
+ { in: "HTTP", want: [0, 0, false] },
+ { in: "HTTP/one.one", want: [0, 0, false] },
+ { in: "HTTP/1.1/", want: [0, 0, false] },
+ { in: "HTTP/-1.0", want: [0, 0, false] },
+ { in: "HTTP/0.-1", want: [0, 0, false] },
+ { in: "HTTP/", want: [0, 0, false] },
+ { in: "HTTP/1,0", want: [0, 0, false] }
+ ];
+ for (const t of testCases) {
+ const r = parseHTTPVersion(t.in);
+ assertEquals(r, t.want, t.in);
+ }
+ }
+});
+
runIfMain(import.meta);