0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

Revert "http: delete conn parameter in readRequest" (denoland/deno_std#550)

This reverts commit 209183e248.
Fixes: denoland/deno_std#441
Original: 3e17815c7e
This commit is contained in:
Bartek Iwańczuk 2019-08-06 00:03:55 +02:00 committed by Bert Belder
parent 782ebfbc0f
commit 50fdccb175
2 changed files with 36 additions and 3 deletions

View file

@ -104,6 +104,7 @@ export class ServerRequest {
protoMinor!: number;
protoMajor!: number;
headers!: Headers;
conn!: Conn;
r!: BufReader;
w!: BufWriter;
done: Deferred<void> = deferred();
@ -283,6 +284,7 @@ export function parseHTTPVersion(vers: string): [number, number] {
}
export async function readRequest(
conn: Conn,
bufr: BufReader
): Promise<ServerRequest | Deno.EOF> {
const tp = new TextProtoReader(bufr);
@ -292,6 +294,7 @@ export async function readRequest(
if (headers === Deno.EOF) throw new UnexpectedEOFError();
const req = new ServerRequest();
req.conn = conn;
req.r = bufr;
[req.method, req.url, req.proto] = firstLine.split(" ", 3);
[req.protoMinor, req.protoMajor] = parseHTTPVersion(req.proto);
@ -321,7 +324,7 @@ export class Server implements AsyncIterable<ServerRequest> {
while (!this.closing) {
try {
req = await readRequest(bufr);
req = await readRequest(conn, bufr);
} catch (e) {
err = e;
break;

View file

@ -74,6 +74,21 @@ test(async function responseWrite(): Promise<void> {
const request = new ServerRequest();
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);
assertEquals(buf.toString(), testCase.raw);
await request.done;
@ -318,6 +333,21 @@ test(async function writeStringReaderResponse(): Promise<void> {
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> {
let input = `GET / HTTP/1.1
malformedHeader
@ -325,7 +355,7 @@ malformedHeader
const reader = new BufReader(new StringReader(input));
let err;
try {
await readRequest(reader);
await readRequest(mockConn, reader);
} catch (e) {
err = e;
}
@ -404,7 +434,7 @@ test(async function testReadRequestError(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let req: any;
try {
req = await readRequest(reader);
req = await readRequest(mockConn, reader);
} catch (e) {
err = e;
}