1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 10:07:54 -05:00
This commit is contained in:
Yoshiya Hinosawa 2024-09-26 13:31:06 +09:00
parent a32ea23dea
commit 33c4efac51
No known key found for this signature in database
GPG key ID: 9017DB4559488785
2 changed files with 126 additions and 125 deletions

View file

@ -333,7 +333,10 @@ pub fn take_network_stream_resource(
if let Ok(resource_rc) = resource_table.take::<TcpStreamResource>(stream_rid) if let Ok(resource_rc) = resource_table.take::<TcpStreamResource>(stream_rid)
{ {
// This TCP connection might be used somewhere else. // This TCP connection might be used somewhere else.
let resource: crate::io::FullDuplexResource<tokio::net::tcp::OwnedReadHalf, tokio::net::tcp::OwnedWriteHalf> = Rc::try_unwrap(resource_rc) let resource: crate::io::FullDuplexResource<
tokio::net::tcp::OwnedReadHalf,
tokio::net::tcp::OwnedWriteHalf,
> = Rc::try_unwrap(resource_rc)
.map_err(|_| bad_resource("TCP stream is currently in use"))?; .map_err(|_| bad_resource("TCP stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner(); let (read_half, write_half) = resource.into_inner();
let tcp_stream = read_half.reunite(write_half)?; let tcp_stream = read_half.reunite(write_half)?;

View file

@ -452,68 +452,66 @@ Deno.test("[node/http] http.IncomingMessage can be created without url", () => {
}); });
*/ */
Deno.test( Deno.test("[node/http] send request with non-chunked body", {
"[node/http] send request with non-chunked body", ignore: true,
{ ignore: true }, }, async () => {
async () => { let requestHeaders: Headers;
let requestHeaders: Headers; let requestBody = "";
let requestBody = "";
const hostname = "localhost"; const hostname = "localhost";
const port = 4505; const port = 4505;
const handler = async (req: Request) => { const handler = async (req: Request) => {
requestHeaders = req.headers; requestHeaders = req.headers;
requestBody = await req.text(); requestBody = await req.text();
return new Response("ok"); return new Response("ok");
}; };
const abortController = new AbortController(); const abortController = new AbortController();
const servePromise = Deno.serve({ const servePromise = Deno.serve({
// TODO(k3k): Enable this line for better compatibility with Node.js // TODO(k3k): Enable this line for better compatibility with Node.js
// hostname, // hostname,
port, port,
signal: abortController.signal, signal: abortController.signal,
onListen: undefined, onListen: undefined,
}, handler).finished; }, handler).finished;
const opts: RequestOptions = { const opts: RequestOptions = {
host: hostname, host: hostname,
port, port,
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "text/plain; charset=utf-8", "Content-Type": "text/plain; charset=utf-8",
"Content-Length": "11", "Content-Length": "11",
}, },
}; };
const req = http.request(opts, (res) => { const req = http.request(opts, (res) => {
res.on("data", () => {}); res.on("data", () => {});
res.on("end", () => { res.on("end", () => {
abortController.abort(); abortController.abort();
});
assertEquals(res.statusCode, 200);
assertEquals(requestHeaders.get("content-length"), "11");
assertEquals(requestHeaders.has("transfer-encoding"), false);
assertEquals(requestBody, "hello world");
}); });
req.on("socket", (socket) => { assertEquals(res.statusCode, 200);
assert(socket.writable); assertEquals(requestHeaders.get("content-length"), "11");
assert(socket.readable); assertEquals(requestHeaders.has("transfer-encoding"), false);
socket.setKeepAlive(); assertEquals(requestBody, "hello world");
socket.destroy(); });
socket.setTimeout(100); req.on("socket", (socket) => {
}); assert(socket.writable);
req.write("hello "); assert(socket.readable);
req.write("world"); socket.setKeepAlive();
req.end(); socket.destroy();
socket.setTimeout(100);
});
req.write("hello ");
req.write("world");
req.end();
await Promise.all([ await Promise.all([
servePromise, servePromise,
// wait 100ms because of the socket.setTimeout(100) above // wait 100ms because of the socket.setTimeout(100) above
// in order to not cause a flaky test sanitizer failure // in order to not cause a flaky test sanitizer failure
await new Promise((resolve) => setTimeout(resolve, 100)), await new Promise((resolve) => setTimeout(resolve, 100)),
]); ]);
}, });
);
Deno.test("[node/http] send request with chunked body", async () => { Deno.test("[node/http] send request with chunked body", async () => {
let requestHeaders: Headers; let requestHeaders: Headers;
@ -694,31 +692,29 @@ Deno.test("[node/http] ClientRequest handle non-string headers", {
assertEquals(headers!["1"], "2"); assertEquals(headers!["1"], "2");
}); });
Deno.test( Deno.test("[node/http] ClientRequest uses HTTP/1.1", {
"[node/http] ClientRequest uses HTTP/1.1", ignore: true,
{ ignore: true }, }, async () => {
async () => { let body = "";
let body = ""; const { promise, resolve, reject } = Promise.withResolvers<void>();
const { promise, resolve, reject } = Promise.withResolvers<void>(); const req = https.request("https://localhost:5545/http_version", {
const req = https.request("https://localhost:5545/http_version", { method: "POST",
method: "POST", headers: { 1: 2 },
headers: { 1: 2 }, }, (resp) => {
}, (resp) => { resp.on("data", (chunk) => {
resp.on("data", (chunk) => { body += chunk;
body += chunk;
});
resp.on("end", () => {
resolve();
});
}); });
req.once("error", (e) => reject(e));
req.end(); resp.on("end", () => {
await promise; resolve();
console.log(body); });
assertEquals(body, "HTTP/1.1"); });
}, req.once("error", (e) => reject(e));
); req.end();
await promise;
console.log(body);
assertEquals(body, "HTTP/1.1");
});
Deno.test("[node/http] ClientRequest setTimeout", async () => { Deno.test("[node/http] ClientRequest setTimeout", async () => {
let body = ""; let body = "";
@ -806,30 +802,28 @@ Deno.test("[node/http] ClientRequest PUT", async () => {
assertEquals(body, "hello world"); assertEquals(body, "hello world");
}); });
Deno.test( Deno.test("[node/http] ClientRequest search params", {
"[node/http] ClientRequest search params", ignore: true,
{ ignore: true }, }, async () => {
async () => { let body = "";
let body = ""; const { promise, resolve, reject } = Promise.withResolvers<void>();
const { promise, resolve, reject } = Promise.withResolvers<void>(); const req = http.request({
const req = http.request({ host: "localhost:4545",
host: "localhost:4545", path: "search_params?foo=bar",
path: "search_params?foo=bar", }, (resp) => {
}, (resp) => { resp.on("data", (chunk) => {
resp.on("data", (chunk) => { body += chunk;
body += chunk;
});
resp.on("end", () => {
resolve();
});
}); });
req.once("error", (e) => reject(e));
req.end(); resp.on("end", () => {
await promise; resolve();
assertEquals(body, "foo=bar"); });
}, });
); req.once("error", (e) => reject(e));
req.end();
await promise;
assertEquals(body, "foo=bar");
});
Deno.test("[node/http] HTTPS server", async () => { Deno.test("[node/http] HTTPS server", async () => {
const deferred = Promise.withResolvers<void>(); const deferred = Promise.withResolvers<void>();
@ -1025,7 +1019,9 @@ Deno.test(
Deno.test( Deno.test(
"[node/http] client destroy before sending request should not error", "[node/http] client destroy before sending request should not error",
{ ignore: true }, {
ignore: true,
},
() => { () => {
const request = http.request("http://localhost:5929/"); const request = http.request("http://localhost:5929/");
// Calling this would throw // Calling this would throw
@ -1033,24 +1029,22 @@ Deno.test(
}, },
); );
Deno.test( Deno.test("[node/http] destroyed requests should not be sent", {
"[node/http] destroyed requests should not be sent", ignore: true,
{ ignore: true }, }, async () => {
async () => { let receivedRequest = false;
let receivedRequest = false; const server = Deno.serve(() => {
const server = Deno.serve(() => { receivedRequest = true;
receivedRequest = true; return new Response(null);
return new Response(null); });
}); const request = http.request(`http://localhost:${server.addr.port}/`);
const request = http.request(`http://localhost:${server.addr.port}/`); request.destroy();
request.destroy(); request.end("hello");
request.end("hello");
await new Promise((r) => setTimeout(r, 500)); await new Promise((r) => setTimeout(r, 500));
assertEquals(receivedRequest, false); assertEquals(receivedRequest, false);
await server.shutdown(); await server.shutdown();
}, });
);
Deno.test("[node/http] node:http exports globalAgent", async () => { Deno.test("[node/http] node:http exports globalAgent", async () => {
const http = await import("node:http"); const http = await import("node:http");
@ -1078,7 +1072,9 @@ Deno.test("[node/https] node:https exports globalAgent", async () => {
Deno.test( Deno.test(
"[node/http] node:http request.setHeader(header, null) doesn't throw", "[node/http] node:http request.setHeader(header, null) doesn't throw",
{ ignore: true }, {
ignore: true,
},
() => { () => {
{ {
const req = http.request("http://localhost:4545/"); const req = http.request("http://localhost:4545/");
@ -1634,7 +1630,9 @@ Deno.test("[node/http] In ClientRequest, option.hostname has precedence over opt
Deno.test( Deno.test(
"[node/http] upgraded socket closes when the server closed without closing handshake", "[node/http] upgraded socket closes when the server closed without closing handshake",
{ ignore: true }, {
ignore: true,
},
async () => { async () => {
const clientSocketClosed = Promise.withResolvers<void>(); const clientSocketClosed = Promise.withResolvers<void>();
const serverProcessClosed = Promise.withResolvers<void>(); const serverProcessClosed = Promise.withResolvers<void>();