Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[http] delete conn parameter in readRequest #430

Merged
merged 3 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export class ServerRequest {
method: string;
proto: string;
headers: Headers;
conn: Conn;
r: BufReader;
w: BufWriter;
done: Deferred<void> = deferred();
Expand Down Expand Up @@ -199,13 +198,10 @@ export class ServerRequest {
}

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 @@ -234,12 +230,14 @@ 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;

while (!this.closing) {
[req, bufStateErr] = await readRequest(conn, bufr);
[req, bufStateErr] = await readRequest(bufr);
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: 0 additions & 15 deletions http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ 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