mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
fix(ext/http): reading headers with ongoing body reader (#15161)
This commit is contained in:
parent
dcd05d4cb9
commit
5b26a4a30e
3 changed files with 77 additions and 9 deletions
|
@ -73,6 +73,68 @@ Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
|
|||
await promise;
|
||||
});
|
||||
|
||||
// https://github.com/denoland/deno/issues/15107
|
||||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpLazyHeadersIssue15107() {
|
||||
let headers: Headers;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 2333 });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const e = await httpConn.nextRequest();
|
||||
assert(e);
|
||||
const { request } = e;
|
||||
request.text();
|
||||
headers = request.headers;
|
||||
httpConn.close();
|
||||
})();
|
||||
|
||||
const conn = await Deno.connect({ port: 2333 });
|
||||
// Send GET request with a body + content-length.
|
||||
const encoder = new TextEncoder();
|
||||
const body =
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:2333\r\nContent-Length: 5\r\n\r\n12345`;
|
||||
const writeResult = await conn.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
await promise;
|
||||
conn.close();
|
||||
assertEquals(headers!.get("content-length"), "5");
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpReadHeadersAfterClose() {
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 2334 });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const e = await httpConn.nextRequest();
|
||||
assert(e);
|
||||
const { request, respondWith } = e;
|
||||
|
||||
await request.text(); // Read body
|
||||
await respondWith(new Response("Hello World")); // Closes request
|
||||
|
||||
assertThrows(() => request.headers, TypeError, "request closed");
|
||||
httpConn.close();
|
||||
})();
|
||||
|
||||
const conn = await Deno.connect({ port: 2334 });
|
||||
// Send GET request with a body + content-length.
|
||||
const encoder = new TextEncoder();
|
||||
const body =
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:2333\r\nContent-Length: 5\r\n\r\n12345`;
|
||||
const writeResult = await conn.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
await promise;
|
||||
conn.close();
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpServerGetRequestBody() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue