summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-11-08 18:15:26 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-11-08 18:15:26 -0500
commit9b78509ceb975df3dc9d795c7310dcc4c73436a3 (patch)
treea33080b946ecec735795de9543f406cf0c44789d
parent80b2067030abdf9f51b1d0eb9ceaaf76c2d09bfb (diff)
wip
Original: https://github.com/denoland/deno_std/commit/ad578ab6fe75dd41585be741e378b92645258b28
-rw-r--r--bufio.ts10
-rw-r--r--http.ts21
2 files changed, 16 insertions, 15 deletions
diff --git a/bufio.ts b/bufio.ts
index 8ff02b7e9..dccd3afc0 100644
--- a/bufio.ts
+++ b/bufio.ts
@@ -323,3 +323,13 @@ export class BufReader implements Reader {
return [this.buf.subarray(this.r, this.r + n), err];
}
}
+
+/** BufWriter implements buffering for an deno.Writer object.
+ * If an error occurs writing to a Writer, no more data will be
+ * accepted and all subsequent writes, and flush(), will return the error.
+ * After all data has been written, the client should call the
+ * flush() method to guarantee all data has been forwarded to
+ * the underlying deno.Writer.
+ */
+export class BufWriter implements Writer {
+}
diff --git a/http.ts b/http.ts
index c7ac88879..c33bc97a2 100644
--- a/http.ts
+++ b/http.ts
@@ -33,8 +33,9 @@ class ServerRequest {
url: string;
method: string;
proto: string;
+ headers: Headers;
- respond(r: Response = { status: 200 }): Promise<void> {
+ respond(r: Response): Promise<void> {
throw Error("not implemented");
}
}
@@ -43,25 +44,15 @@ async function readRequest(b: BufReader): Promise<ServerRequest> {
const tp = new TextProtoReader(b);
const req = new ServerRequest();
- // First line: GET /index.html HTTP/1.0
let s: string;
let err: BufState;
+
+ // First line: GET /index.html HTTP/1.0
[s, err] = await tp.readLine();
- const { method, url, proto } = parseRequestLine(s);
- req.method = method;
- req.url = url;
- req.proto = proto;
+ [req.method, req.url, req.proto] = s.split(" ", 3);
- let headers: Headers;
- [headers, err] = await tp.readMIMEHeader();
+ [req.headers, err] = await tp.readMIMEHeader();
return req;
}
-// Returns [method, url, proto]
-function parseRequestLine(
- line: string
-): { method: string; url: string; proto: string } {
- let [method, url, proto] = line.split(" ", 3);
- return { method, url, proto };
-}