diff options
Diffstat (limited to 'std/http/io_test.ts')
-rw-r--r-- | std/http/io_test.ts | 18 |
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 |