mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
fix(http): remove unwrap() in HTTP bindings (#11130)
This commit is contained in:
parent
098a7c8886
commit
9e875b2a23
2 changed files with 46 additions and 1 deletions
|
@ -586,3 +586,48 @@ unitTest({ perms: { net: true } }, async function httpRequestLatin1Headers() {
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest(
|
||||||
|
{ perms: { net: true } },
|
||||||
|
async function httpServerRequestWithoutPath() {
|
||||||
|
const promise = (async () => {
|
||||||
|
const listener = Deno.listen({ port: 4501 });
|
||||||
|
for await (const conn of listener) {
|
||||||
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
for await (const { request, respondWith } of httpConn) {
|
||||||
|
assertEquals(new URL(request.url).href, "http://127.0.0.1/");
|
||||||
|
assertEquals(await request.text(), "");
|
||||||
|
respondWith(new Response());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const clientConn = await Deno.connect({ port: 4501 });
|
||||||
|
|
||||||
|
async function writeRequest(conn: Deno.Conn) {
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
|
const w = new BufWriter(conn);
|
||||||
|
const r = new BufReader(conn);
|
||||||
|
const body =
|
||||||
|
`CONNECT 127.0.0.1:4501 HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
||||||
|
const writeResult = await w.write(encoder.encode(body));
|
||||||
|
assertEquals(body.length, writeResult);
|
||||||
|
await w.flush();
|
||||||
|
const tpr = new TextProtoReader(r);
|
||||||
|
const statusLine = await tpr.readLine();
|
||||||
|
assert(statusLine !== null);
|
||||||
|
const m = statusLine.match(/^(.+?) (.+?) (.+?)$/);
|
||||||
|
assert(m !== null, "must be matched");
|
||||||
|
const [_, _proto, status, _ok] = m;
|
||||||
|
assertEquals(status, "200");
|
||||||
|
const headers = await tpr.readMIMEHeader();
|
||||||
|
assert(headers !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
await writeRequest(clientConn);
|
||||||
|
clientConn.close();
|
||||||
|
await promise;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
@ -222,7 +222,7 @@ async fn op_http_request_next(
|
||||||
} else {
|
} else {
|
||||||
Cow::Owned(conn_resource.addr.to_string())
|
Cow::Owned(conn_resource.addr.to_string())
|
||||||
};
|
};
|
||||||
let path = req.uri().path_and_query().unwrap();
|
let path = req.uri().path_and_query().map_or("/", |p| p.as_str());
|
||||||
format!("{}://{}{}", scheme, host, path)
|
format!("{}://{}{}", scheme, host, path)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue