From c23092c5f836340a9fe91f2e7d4ff3eea7601d6c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 23 May 2019 22:25:08 +0300 Subject: [PATCH] Revert "http: delete conn parameter in readRequest (#430)" This reverts commit 209183e24812095a40e48e60484f80a5a254b1c3. --- http/server.ts | 6 ++++-- http/server_test.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/http/server.ts b/http/server.ts index baccaacfb95c..e1aab60cb696 100644 --- a/http/server.ts +++ b/http/server.ts @@ -103,6 +103,7 @@ export class ServerRequest { method: string; proto: string; headers: Headers; + conn: Conn; r: BufReader; w: BufWriter; done: Deferred = deferred(); @@ -216,10 +217,13 @@ function fixLength(req: ServerRequest): void { } export async function readRequest( + conn: Conn, bufr: BufReader ): Promise<[ServerRequest, BufState]> { const req = new ServerRequest(); + req.conn = conn; req.r = bufr; + req.w = new BufWriter(conn); const tp = new TextProtoReader(bufr); let err: BufState; // First line: GET /index.html HTTP/1.0 @@ -253,7 +257,6 @@ export class Server implements AsyncIterable { conn: Conn ): AsyncIterableIterator { const bufr = new BufReader(conn); - const w = new BufWriter(conn); let bufStateErr: BufState; let req: ServerRequest; @@ -264,7 +267,6 @@ export class Server implements AsyncIterable { bufStateErr = err; } if (bufStateErr) break; - req.w = w; yield req; // Wait for the request to be processed before we accept a new request on // this connection. diff --git a/http/server_test.ts b/http/server_test.ts index 705fea1baeb6..612e7f99bf0b 100644 --- a/http/server_test.ts +++ b/http/server_test.ts @@ -61,6 +61,21 @@ test(async function responseWrite(): Promise { const request = new ServerRequest(); request.w = bufw; + request.conn = { + localAddr: "", + remoteAddr: "", + rid: -1, + closeRead: (): void => {}, + closeWrite: (): void => {}, + read: async (): Promise => { + return { eof: true, nread: 0 }; + }, + write: async (): Promise => { + return -1; + }, + close: (): void => {} + }; + await request.respond(testCase.response); assertEquals(buf.toString(), testCase.raw); await request.done;