Skip to content

Commit

Permalink
Remove incorrect request error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Feb 15, 2020
1 parent f4c3457 commit 7e7896b
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions std/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,11 @@ class EventType<T> {
}

export class Server implements AsyncIterable<ServerRequest> {
private closing = false;
private closed = deferred<void>();

constructor(public listener: Listener) {}

close(): void {
this.closing = true;
this.closed.resolve();
this.listener.close();
}
Expand All @@ -489,17 +487,15 @@ export class Server implements AsyncIterable<ServerRequest> {
): AsyncIterableIterator<ServerRequest> {
const bufr = new BufReader(conn);
const w = new BufWriter(conn);
let req: ServerRequest | Deno.EOF;
let err: Error | undefined;

while (true) {
let req: ServerRequest | Deno.EOF;
try {
req = await Promise.race([
readRequest(conn, bufr),
this.closed.then((): Deno.EOF => Deno.EOF)
]);
} catch (e) {
err = e;
break;
}
if (req === Deno.EOF) {
Expand All @@ -520,24 +516,6 @@ export class Server implements AsyncIterable<ServerRequest> {
}
}

if (req === Deno.EOF) {
// The connection was gracefully closed.
} else if (err && req) {
// An error was thrown while parsing request headers.
try {
await writeResponse(req.w, {
status: 400,
body: encoder.encode(`${err.message}\r\n\r\n`)
});
} catch (_) {
// The connection is destroyed.
// Ignores the error.
}
} else if (this.closing) {
// There are more requests incoming but the server is closing.
// TODO(ry): send a back a HTTP 503 Service Unavailable status.
}

conn.close();
}

Expand Down

0 comments on commit 7e7896b

Please sign in to comment.