mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
fix(std/http): parsing of HTTP version header (#8902)
This commit is contained in:
parent
e568ddf996
commit
0163cedd80
2 changed files with 12 additions and 1 deletions
|
@ -346,7 +346,7 @@ export async function readRequest(
|
||||||
req.conn = conn;
|
req.conn = conn;
|
||||||
req.r = bufr;
|
req.r = bufr;
|
||||||
[req.method, req.url, req.proto] = firstLine.split(" ", 3);
|
[req.method, req.url, req.proto] = firstLine.split(" ", 3);
|
||||||
[req.protoMinor, req.protoMajor] = parseHTTPVersion(req.proto);
|
[req.protoMajor, req.protoMinor] = parseHTTPVersion(req.proto);
|
||||||
req.headers = headers;
|
req.headers = headers;
|
||||||
fixLength(req);
|
fixLength(req);
|
||||||
return req;
|
return req;
|
||||||
|
|
|
@ -407,6 +407,11 @@ Deno.test("testReadRequestError", async function (): Promise<void> {
|
||||||
in: "GET / HTTP/1.1\r\nheader:foo\r\n",
|
in: "GET / HTTP/1.1\r\nheader:foo\r\n",
|
||||||
err: Deno.errors.UnexpectedEof,
|
err: Deno.errors.UnexpectedEof,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
in: "POST / HTTP/1.0\r\n\r\n",
|
||||||
|
headers: [],
|
||||||
|
version: true,
|
||||||
|
},
|
||||||
{ in: "", eof: true },
|
{ in: "", eof: true },
|
||||||
{
|
{
|
||||||
in: "HEAD / HTTP/1.1\r\nContent-Length:4\r\n\r\n",
|
in: "HEAD / HTTP/1.1\r\nContent-Length:4\r\n\r\n",
|
||||||
|
@ -472,6 +477,12 @@ Deno.test("testReadRequestError", async function (): Promise<void> {
|
||||||
assert(err instanceof (test.err as typeof Deno.errors.UnexpectedEof));
|
assert(err instanceof (test.err as typeof Deno.errors.UnexpectedEof));
|
||||||
} else {
|
} else {
|
||||||
assert(req instanceof ServerRequest);
|
assert(req instanceof ServerRequest);
|
||||||
|
if (test.version) {
|
||||||
|
// return value order of parseHTTPVersion() function have to match with [req.protoMajor, req.protoMinor];
|
||||||
|
const version = parseHTTPVersion(test.in.split(" ", 3)[2]);
|
||||||
|
assertEquals(req.protoMajor, version[0]);
|
||||||
|
assertEquals(req.protoMinor, version[1]);
|
||||||
|
}
|
||||||
assert(test.headers);
|
assert(test.headers);
|
||||||
assertEquals(err, undefined);
|
assertEquals(err, undefined);
|
||||||
assertNotEquals(req, null);
|
assertNotEquals(req, null);
|
||||||
|
|
Loading…
Add table
Reference in a new issue