summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
Diffstat (limited to 'http')
-rwxr-xr-xhttp/file_server.ts2
-rw-r--r--http/file_server_test.ts4
-rw-r--r--http/server.ts24
3 files changed, 18 insertions, 12 deletions
diff --git a/http/file_server.ts b/http/file_server.ts
index 659e9ba56..83de37364 100755
--- a/http/file_server.ts
+++ b/http/file_server.ts
@@ -188,7 +188,7 @@ async function serveDir(
async function serveFallback(req: ServerRequest, e: Error): Promise<Response> {
if (
e instanceof Deno.DenoError &&
- (e as Deno.DenoError<any>).kind === ErrorKind.NotFound
+ (e as Deno.DenoError<Deno.ErrorKind.NotFound>).kind === ErrorKind.NotFound
) {
return {
status: 404,
diff --git a/http/file_server_test.ts b/http/file_server_test.ts
index 15f052e6e..31ddca08e 100644
--- a/http/file_server_test.ts
+++ b/http/file_server_test.ts
@@ -7,7 +7,7 @@ import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
let fileServer;
-async function startFileServer() {
+async function startFileServer(): Promise<void> {
fileServer = run({
args: [
"deno",
@@ -25,7 +25,7 @@ async function startFileServer() {
assert(err == null);
assert(s.includes("server listening"));
}
-function killFileServer() {
+function killFileServer(): void {
fileServer.close();
fileServer.stdout.close();
}
diff --git a/http/server.ts b/http/server.ts
index 5cf658cf3..17295f739 100644
--- a/http/server.ts
+++ b/http/server.ts
@@ -36,7 +36,7 @@ export function setContentLength(r: Response): void {
}
}
}
-async function writeChunkedBody(w: Writer, r: Reader) {
+async function writeChunkedBody(w: Writer, r: Reader): Promise<void> {
const writer = bufWriter(w);
const encoder = new TextEncoder();
@@ -123,7 +123,7 @@ export class ServerRequest {
r: BufReader;
w: BufWriter;
- public async *bodyStream() {
+ public async *bodyStream(): AsyncIterableIterator<Uint8Array> {
if (this.headers.has("content-length")) {
const len = +this.headers.get("content-length");
if (Number.isNaN(len)) {
@@ -263,7 +263,11 @@ async function readRequest(
return [req, err];
}
-function maybeHandleReq(env: ServeEnv, conn: Conn, maybeReq: any) {
+function maybeHandleReq(
+ env: ServeEnv,
+ conn: Conn,
+ maybeReq: [ServerRequest, BufState]
+): void {
const [req, _err] = maybeReq;
if (_err) {
conn.close(); // assume EOF for now...
@@ -273,11 +277,13 @@ function maybeHandleReq(env: ServeEnv, conn: Conn, maybeReq: any) {
env.serveDeferred.resolve(); // signal while loop to process it
}
-function serveConn(env: ServeEnv, conn: Conn, bufr?: BufReader) {
+function serveConn(env: ServeEnv, conn: Conn, bufr?: BufReader): void {
readRequest(conn, bufr).then(maybeHandleReq.bind(null, env, conn));
}
-export async function* serve(addr: string) {
+export async function* serve(
+ addr: string
+): AsyncIterableIterator<ServerRequest> {
const listener = listen("tcp", addr);
const env: ServeEnv = {
reqQueue: [], // in case multiple promises are ready
@@ -285,9 +291,9 @@ export async function* serve(addr: string) {
};
// Routine that keeps calling accept
- let handleConn = (_conn: Conn) => {};
- let scheduleAccept = () => {};
- const acceptRoutine = () => {
+ let handleConn = (_conn: Conn): void => {};
+ let scheduleAccept = (): void => {};
+ const acceptRoutine = (): void => {
scheduleAccept = () => {
listener.accept().then(handleConn);
};
@@ -320,7 +326,7 @@ export async function* serve(addr: string) {
export async function listenAndServe(
addr: string,
handler: (req: ServerRequest) => void
-) {
+): Promise<void> {
const server = serve(addr);
for await (const request of server) {