diff options
| author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-12-11 17:56:32 -0500 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-11 17:56:32 -0500 |
| commit | b94530332910c0b85553dc91fa1912bce308df3c (patch) | |
| tree | 86034754d12b04aa8ee5afe541c4b98b78ca5ed0 /http.ts | |
| parent | a691d9257b89cc210de6371138508c76aa288aba (diff) | |
Serve directory for file server & Fix bufio flush bug (denoland/deno_std#15)
Original: https://github.com/denoland/deno_std/commit/b78f4e9fbd477b026f1a309c64f4f8f75cd4d5d6
Diffstat (limited to 'http.ts')
| -rw-r--r-- | http.ts | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -82,7 +82,10 @@ export async function* serve(addr: string) { listener.close(); } -export async function listenAndServe(addr: string, handler: (req: ServerRequest) => void) { +export async function listenAndServe( + addr: string, + handler: (req: ServerRequest) => void +) { const server = serve(addr); for await (const request of server) { @@ -90,23 +93,23 @@ export async function listenAndServe(addr: string, handler: (req: ServerRequest) } } -interface Response { +export interface Response { status?: number; headers?: Headers; body?: Uint8Array; } -function setContentLength(r: Response): void { +export function setContentLength(r: Response): void { if (!r.headers) { r.headers = new Headers(); } if (!r.headers.has("content-length")) { - const bodyLength = r.body ? r.body.byteLength : 0 + const bodyLength = r.body ? r.body.byteLength : 0; r.headers.append("Content-Length", bodyLength.toString()); } } -class ServerRequest { +export class ServerRequest { url: string; method: string; proto: string; |
