mirror of
https://github.com/denoland/deno.git
synced 2024-10-30 09:08:00 -04:00
Revert "http: delete conn parameter in readRequest" (denoland/deno_std#550)
This reverts commit209183e248
. Fixes: denoland/deno_std#441 Original:3e17815c7e
This commit is contained in:
parent
782ebfbc0f
commit
50fdccb175
2 changed files with 36 additions and 3 deletions
|
@ -104,6 +104,7 @@ export class ServerRequest {
|
||||||
protoMinor!: number;
|
protoMinor!: number;
|
||||||
protoMajor!: number;
|
protoMajor!: number;
|
||||||
headers!: Headers;
|
headers!: Headers;
|
||||||
|
conn!: Conn;
|
||||||
r!: BufReader;
|
r!: BufReader;
|
||||||
w!: BufWriter;
|
w!: BufWriter;
|
||||||
done: Deferred<void> = deferred();
|
done: Deferred<void> = deferred();
|
||||||
|
@ -283,6 +284,7 @@ export function parseHTTPVersion(vers: string): [number, number] {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readRequest(
|
export async function readRequest(
|
||||||
|
conn: Conn,
|
||||||
bufr: BufReader
|
bufr: BufReader
|
||||||
): Promise<ServerRequest | Deno.EOF> {
|
): Promise<ServerRequest | Deno.EOF> {
|
||||||
const tp = new TextProtoReader(bufr);
|
const tp = new TextProtoReader(bufr);
|
||||||
|
@ -292,6 +294,7 @@ export async function readRequest(
|
||||||
if (headers === Deno.EOF) throw new UnexpectedEOFError();
|
if (headers === Deno.EOF) throw new UnexpectedEOFError();
|
||||||
|
|
||||||
const req = new ServerRequest();
|
const req = new ServerRequest();
|
||||||
|
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.protoMinor, req.protoMajor] = parseHTTPVersion(req.proto);
|
||||||
|
@ -321,7 +324,7 @@ export class Server implements AsyncIterable<ServerRequest> {
|
||||||
|
|
||||||
while (!this.closing) {
|
while (!this.closing) {
|
||||||
try {
|
try {
|
||||||
req = await readRequest(bufr);
|
req = await readRequest(conn, bufr);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -74,6 +74,21 @@ test(async function responseWrite(): Promise<void> {
|
||||||
const request = new ServerRequest();
|
const request = new ServerRequest();
|
||||||
request.w = bufw;
|
request.w = bufw;
|
||||||
|
|
||||||
|
request.conn = {
|
||||||
|
localAddr: "",
|
||||||
|
remoteAddr: "",
|
||||||
|
rid: -1,
|
||||||
|
closeRead: (): void => {},
|
||||||
|
closeWrite: (): void => {},
|
||||||
|
read: async (): Promise<number | Deno.EOF> => {
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
write: async (): Promise<number> => {
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
close: (): void => {}
|
||||||
|
};
|
||||||
|
|
||||||
await request.respond(testCase.response);
|
await request.respond(testCase.response);
|
||||||
assertEquals(buf.toString(), testCase.raw);
|
assertEquals(buf.toString(), testCase.raw);
|
||||||
await request.done;
|
await request.done;
|
||||||
|
@ -318,6 +333,21 @@ test(async function writeStringReaderResponse(): Promise<void> {
|
||||||
assertEquals(r.more, false);
|
assertEquals(r.more, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mockConn = {
|
||||||
|
localAddr: "",
|
||||||
|
remoteAddr: "",
|
||||||
|
rid: -1,
|
||||||
|
closeRead: (): void => {},
|
||||||
|
closeWrite: (): void => {},
|
||||||
|
read: async (): Promise<number | Deno.EOF> => {
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
write: async (): Promise<number> => {
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
|
close: (): void => {}
|
||||||
|
};
|
||||||
|
|
||||||
test(async function readRequestError(): Promise<void> {
|
test(async function readRequestError(): Promise<void> {
|
||||||
let input = `GET / HTTP/1.1
|
let input = `GET / HTTP/1.1
|
||||||
malformedHeader
|
malformedHeader
|
||||||
|
@ -325,7 +355,7 @@ malformedHeader
|
||||||
const reader = new BufReader(new StringReader(input));
|
const reader = new BufReader(new StringReader(input));
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
await readRequest(reader);
|
await readRequest(mockConn, reader);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
@ -404,7 +434,7 @@ test(async function testReadRequestError(): Promise<void> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
let req: any;
|
let req: any;
|
||||||
try {
|
try {
|
||||||
req = await readRequest(reader);
|
req = await readRequest(mockConn, reader);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue