summaryrefslogtreecommitdiff
path: root/http.ts
diff options
context:
space:
mode:
Diffstat (limited to 'http.ts')
-rw-r--r--http.ts21
1 files changed, 6 insertions, 15 deletions
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 };
-}