mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
http: delete conn parameter in readRequest (#430)
To bring it inline with Go API
This commit is contained in:
parent
aad0896346
commit
209183e248
2 changed files with 3 additions and 20 deletions
|
@ -104,7 +104,6 @@ export class ServerRequest {
|
||||||
method: string;
|
method: string;
|
||||||
proto: string;
|
proto: string;
|
||||||
headers: Headers;
|
headers: Headers;
|
||||||
conn: Conn;
|
|
||||||
r: BufReader;
|
r: BufReader;
|
||||||
w: BufWriter;
|
w: BufWriter;
|
||||||
done: Deferred<void> = deferred();
|
done: Deferred<void> = deferred();
|
||||||
|
@ -199,13 +198,10 @@ export class ServerRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readRequest(
|
async function readRequest(
|
||||||
conn: Conn,
|
|
||||||
bufr: BufReader
|
bufr: BufReader
|
||||||
): Promise<[ServerRequest, BufState]> {
|
): Promise<[ServerRequest, BufState]> {
|
||||||
const req = new ServerRequest();
|
const req = new ServerRequest();
|
||||||
req.conn = conn;
|
|
||||||
req.r = bufr;
|
req.r = bufr;
|
||||||
req.w = new BufWriter(conn);
|
|
||||||
const tp = new TextProtoReader(bufr);
|
const tp = new TextProtoReader(bufr);
|
||||||
let err: BufState;
|
let err: BufState;
|
||||||
// First line: GET /index.html HTTP/1.0
|
// First line: GET /index.html HTTP/1.0
|
||||||
|
@ -234,12 +230,14 @@ export class Server implements AsyncIterable<ServerRequest> {
|
||||||
conn: Conn
|
conn: Conn
|
||||||
): AsyncIterableIterator<ServerRequest> {
|
): AsyncIterableIterator<ServerRequest> {
|
||||||
const bufr = new BufReader(conn);
|
const bufr = new BufReader(conn);
|
||||||
|
const w = new BufWriter(conn);
|
||||||
let bufStateErr: BufState;
|
let bufStateErr: BufState;
|
||||||
let req: ServerRequest;
|
let req: ServerRequest;
|
||||||
|
|
||||||
while (!this.closing) {
|
while (!this.closing) {
|
||||||
[req, bufStateErr] = await readRequest(conn, bufr);
|
[req, bufStateErr] = await readRequest(bufr);
|
||||||
if (bufStateErr) break;
|
if (bufStateErr) break;
|
||||||
|
req.w = w;
|
||||||
yield req;
|
yield req;
|
||||||
// Wait for the request to be processed before we accept a new request on
|
// Wait for the request to be processed before we accept a new request on
|
||||||
// this connection.
|
// this connection.
|
||||||
|
|
|
@ -49,21 +49,6 @@ test(async function responseWrite(): Promise<void> {
|
||||||
const request = new ServerRequest();
|
const request = new ServerRequest();
|
||||||
request.w = bufw;
|
request.w = bufw;
|
||||||
|
|
||||||
request.conn = {
|
|
||||||
localAddr: "",
|
|
||||||
remoteAddr: "",
|
|
||||||
rid: -1,
|
|
||||||
closeRead: (): void => {},
|
|
||||||
closeWrite: (): void => {},
|
|
||||||
read: async (): Promise<Deno.ReadResult> => {
|
|
||||||
return { eof: true, nread: 0 };
|
|
||||||
},
|
|
||||||
write: async (): Promise<number> => {
|
|
||||||
return -1;
|
|
||||||
},
|
|
||||||
close: (): void => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
await request.respond(testCase.response);
|
await request.respond(testCase.response);
|
||||||
assertEquals(buf.toString(), testCase.raw);
|
assertEquals(buf.toString(), testCase.raw);
|
||||||
await request.done;
|
await request.done;
|
||||||
|
|
Loading…
Reference in a new issue