mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
parent
80b2067030
commit
9b78509ceb
2 changed files with 17 additions and 16 deletions
10
bufio.ts
10
bufio.ts
|
@ -323,3 +323,13 @@ export class BufReader implements Reader {
|
||||||
return [this.buf.subarray(this.r, this.r + n), err];
|
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 {
|
||||||
|
}
|
||||||
|
|
23
http.ts
23
http.ts
|
@ -33,8 +33,9 @@ class ServerRequest {
|
||||||
url: string;
|
url: string;
|
||||||
method: string;
|
method: string;
|
||||||
proto: string;
|
proto: string;
|
||||||
|
headers: Headers;
|
||||||
|
|
||||||
respond(r: Response = { status: 200 }): Promise<void> {
|
respond(r: Response): Promise<void> {
|
||||||
throw Error("not implemented");
|
throw Error("not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,25 +44,15 @@ async function readRequest(b: BufReader): Promise<ServerRequest> {
|
||||||
const tp = new TextProtoReader(b);
|
const tp = new TextProtoReader(b);
|
||||||
const req = new ServerRequest();
|
const req = new ServerRequest();
|
||||||
|
|
||||||
// First line: GET /index.html HTTP/1.0
|
|
||||||
let s: string;
|
let s: string;
|
||||||
let err: BufState;
|
let err: BufState;
|
||||||
[s, err] = await tp.readLine();
|
|
||||||
const { method, url, proto } = parseRequestLine(s);
|
|
||||||
req.method = method;
|
|
||||||
req.url = url;
|
|
||||||
req.proto = proto;
|
|
||||||
|
|
||||||
let headers: Headers;
|
// First line: GET /index.html HTTP/1.0
|
||||||
[headers, err] = await tp.readMIMEHeader();
|
[s, err] = await tp.readLine();
|
||||||
|
[req.method, req.url, req.proto] = s.split(" ", 3);
|
||||||
|
|
||||||
|
[req.headers, err] = await tp.readMIMEHeader();
|
||||||
|
|
||||||
return req;
|
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 };
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue