summaryrefslogtreecommitdiff
path: root/std/http/io_test.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-01 09:24:05 +0100
committerGitHub <noreply@github.com>2020-04-01 10:24:05 +0200
commit017a611131a35ccf5dbfce6a2a665fa569e32ec1 (patch)
tree49f07dfc25f8fdf45dae2f812941f42e9274bea6 /std/http/io_test.ts
parent857d96001d63c1cb847f3f228124d69c40d267e7 (diff)
feat(std/http/server): Respond with 400 on request parse failure (#4551)
Diffstat (limited to 'std/http/io_test.ts')
-rw-r--r--std/http/io_test.ts18
1 files changed, 17 insertions, 1 deletions
diff --git a/std/http/io_test.ts b/std/http/io_test.ts
index 7261964d0..c1d6a921b 100644
--- a/std/http/io_test.ts
+++ b/std/http/io_test.ts
@@ -5,6 +5,7 @@ import {
assert,
assertNotEOF,
assertNotEquals,
+ assertMatch,
} from "../testing/asserts.ts";
import {
bodyReader,
@@ -349,13 +350,28 @@ malformedHeader
`;
const reader = new BufReader(new StringReader(input));
let err;
+ let responseString: string;
try {
- await readRequest(mockConn(), reader);
+ // Capture whatever `readRequest()` attempts to write to the connection on
+ // error. We expect it to be a 400 response.
+ await readRequest(
+ mockConn({
+ write(p: Uint8Array): Promise<number> {
+ responseString = decode(p);
+ return Promise.resolve(p.length);
+ },
+ }),
+ reader
+ );
} catch (e) {
err = e;
}
assert(err instanceof Error);
assertEquals(err.message, "malformed MIME header line: malformedHeader");
+ assertMatch(
+ responseString!,
+ /^HTTP\/1\.1 400 Bad Request\r\ncontent-length: \d+\r\n\r\n.*\r\n\r\n$/ms
+ );
});
// Ported from Go