summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/http_test.ts45
-rw-r--r--runtime/ops/http.rs2
2 files changed, 46 insertions, 1 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 0c7aec155..ad78e1e44 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -586,3 +586,48 @@ unitTest({ perms: { net: true } }, async function httpRequestLatin1Headers() {
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;
+ },
+);
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs
index cd1ac9242..01658c802 100644
--- a/runtime/ops/http.rs
+++ b/runtime/ops/http.rs
@@ -222,7 +222,7 @@ async fn op_http_request_next(
} else {
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)
};