Skip to content

Commit

Permalink
Revert "http: delete conn parameter in readRequest (denoland#430)"
Browse files Browse the repository at this point in the history
This reverts commit 209183e.
  • Loading branch information
ry committed May 23, 2019
1 parent 7a722ce commit c23092c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class ServerRequest {
method: string;
proto: string;
headers: Headers;
conn: Conn;
r: BufReader;
w: BufWriter;
done: Deferred<void> = deferred();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -253,7 +257,6 @@ export class Server implements AsyncIterable<ServerRequest> {
conn: Conn
): AsyncIterableIterator<ServerRequest> {
const bufr = new BufReader(conn);
const w = new BufWriter(conn);
let bufStateErr: BufState;
let req: ServerRequest;

Expand All @@ -264,7 +267,6 @@ export class Server implements AsyncIterable<ServerRequest> {
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.
Expand Down
15 changes: 15 additions & 0 deletions http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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<Deno.ReadResult> => {
return { eof: true, nread: 0 };
},
write: async (): Promise<number> => {
return -1;
},
close: (): void => {}
};

await request.respond(testCase.response);
assertEquals(buf.toString(), testCase.raw);
await request.done;
Expand Down

0 comments on commit c23092c

Please sign in to comment.