mirror of
https://github.com/denoland/deno.git
synced 2025-01-06 22:35:51 -05:00
remove debugs
This commit is contained in:
parent
16be0202ca
commit
4915f342b0
3 changed files with 32 additions and 123 deletions
|
@ -118,7 +118,6 @@ where
|
||||||
.take::<TlsStreamResource>(conn_rid)?;
|
.take::<TlsStreamResource>(conn_rid)?;
|
||||||
let resource = Rc::try_unwrap(resource_rc)
|
let resource = Rc::try_unwrap(resource_rc)
|
||||||
.map_err(|_e| bad_resource("TLS stream is currently in use"));
|
.map_err(|_e| bad_resource("TLS stream is currently in use"));
|
||||||
eprintln!("op_node_http_request_with_conn(tls): {resource:?}");
|
|
||||||
let resource = resource?;
|
let resource = resource?;
|
||||||
let (read_half, write_half) = resource.into_inner();
|
let (read_half, write_half) = resource.into_inner();
|
||||||
let tcp_stream = read_half.unsplit(write_half);
|
let tcp_stream = read_half.unsplit(write_half);
|
||||||
|
@ -144,7 +143,6 @@ where
|
||||||
.take::<TcpStreamResource>(conn_rid)?;
|
.take::<TcpStreamResource>(conn_rid)?;
|
||||||
let resource = Rc::try_unwrap(resource_rc)
|
let resource = 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"));
|
||||||
eprintln!("op_node_http_request_with_conn(tcp): {resource:?}");
|
|
||||||
let resource = resource?;
|
let resource = resource?;
|
||||||
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)?;
|
||||||
|
@ -258,7 +256,6 @@ pub async fn op_node_http_wait_for_connection(
|
||||||
.take::<NodeHttpConnReady>(rid)?;
|
.take::<NodeHttpConnReady>(rid)?;
|
||||||
let resource =
|
let resource =
|
||||||
Rc::try_unwrap(resource).map_err(|_| bad_resource("NodeHttpConnReady"));
|
Rc::try_unwrap(resource).map_err(|_| bad_resource("NodeHttpConnReady"));
|
||||||
eprintln!("op_node_http_wait_for_connection: {resource:?}");
|
|
||||||
let resource = resource?;
|
let resource = resource?;
|
||||||
resource.recv.await?;
|
resource.recv.await?;
|
||||||
Ok(rid)
|
Ok(rid)
|
||||||
|
@ -276,16 +273,12 @@ pub async fn op_node_http_await_response(
|
||||||
.take::<NodeHttpClientResponse>(rid)?;
|
.take::<NodeHttpClientResponse>(rid)?;
|
||||||
let resource = Rc::try_unwrap(resource)
|
let resource = Rc::try_unwrap(resource)
|
||||||
.map_err(|_| bad_resource("NodeHttpClientResponse"));
|
.map_err(|_| bad_resource("NodeHttpClientResponse"));
|
||||||
eprintln!("resource: {resource:?}");
|
|
||||||
let resource = resource?;
|
let resource = resource?;
|
||||||
|
|
||||||
eprintln!("op_node_http_await_response: awating for res");
|
|
||||||
let res = resource.response.await;
|
let res = resource.response.await;
|
||||||
eprintln!("op_node_http_await_response: res: {res:?}");
|
|
||||||
let res = res?;
|
let res = res?;
|
||||||
|
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
eprintln!("op_node_http_await_response: {status}");
|
|
||||||
let mut res_headers = Vec::new();
|
let mut res_headers = Vec::new();
|
||||||
for (key, val) in res.headers().iter() {
|
for (key, val) in res.headers().iter() {
|
||||||
res_headers.push((key.as_str().into(), val.as_bytes().into()));
|
res_headers.push((key.as_str().into(), val.as_bytes().into()));
|
||||||
|
@ -583,7 +576,6 @@ impl Stream for NodeHttpResourceToBodyAdapter {
|
||||||
Ok(buf) if buf.is_empty() => Poll::Ready(None),
|
Ok(buf) if buf.is_empty() => Poll::Ready(None),
|
||||||
Ok(buf) => {
|
Ok(buf) => {
|
||||||
let bytes: Bytes = buf.to_vec().into();
|
let bytes: Bytes = buf.to_vec().into();
|
||||||
eprintln!("buf: {:?}", bytes);
|
|
||||||
this.1 = Some(this.0.clone().read(64 * 1024));
|
this.1 = Some(this.0.clone().read(64 * 1024));
|
||||||
Poll::Ready(Some(Ok(bytes)))
|
Poll::Ready(Some(Ok(bytes)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,11 +391,7 @@ Object.defineProperties(
|
||||||
msg._implicitHeader();
|
msg._implicitHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return msg._send(chunk, encoding, callback);
|
||||||
return msg._send(chunk, encoding, callback);
|
|
||||||
} catch (error) {
|
|
||||||
console.log("error from msg._send()", error);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
|
@ -514,42 +510,23 @@ Object.defineProperties(
|
||||||
/** Right after socket is ready, we need to writeHeader() to setup the request and
|
/** Right after socket is ready, we need to writeHeader() to setup the request and
|
||||||
* client. This is invoked by onSocket(). */
|
* client. This is invoked by onSocket(). */
|
||||||
_flushHeaders() {
|
_flushHeaders() {
|
||||||
console.trace("_flushHeaders", {
|
if (!this._headerSent) {
|
||||||
socket: !!this.socket,
|
|
||||||
headerSent: this._headerSent,
|
|
||||||
});
|
|
||||||
if (this.socket && !this._headerSent) {
|
|
||||||
this._headerSent = true;
|
this._headerSent = true;
|
||||||
this._writeHeader();
|
this._writeHeader();
|
||||||
} else {
|
|
||||||
// deno-lint-ignore no-console
|
|
||||||
console.warn("socket not found");
|
|
||||||
}
|
}
|
||||||
console.trace("_flushHeaders after", {
|
|
||||||
socket: !!this.socket,
|
|
||||||
headerSent: this._headerSent,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
_send(data: any, encoding?: string | null, callback?: () => void) {
|
_send(data: any, encoding?: string | null, callback?: () => void) {
|
||||||
console.trace("send invoked", {
|
|
||||||
data: new TextDecoder().decode(data.slice(-20, -1)),
|
|
||||||
});
|
|
||||||
// if socket is ready, write the data after headers are written.
|
// if socket is ready, write the data after headers are written.
|
||||||
// if socket is not ready, buffer data in outputbuffer.
|
// if socket is not ready, buffer data in outputbuffer.
|
||||||
if (this.socket && !this.socket.connecting) {
|
if (this.socket && !this.socket.connecting) {
|
||||||
console.log("writing headers again:", {
|
|
||||||
headerSent: this._headerSent,
|
|
||||||
header: this._header,
|
|
||||||
});
|
|
||||||
if (!this._headerSent) {
|
if (!this._headerSent) {
|
||||||
this._writeHeader();
|
this._writeHeader();
|
||||||
this._headerSent = true;
|
this._headerSent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._headerSent) {
|
if (this._headerSent) {
|
||||||
console.log("writeRaw invoked");
|
|
||||||
return this._writeRaw(data, encoding, callback);
|
return this._writeRaw(data, encoding, callback);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -599,7 +576,6 @@ Object.defineProperties(
|
||||||
encoding?: string | null,
|
encoding?: string | null,
|
||||||
callback?: () => void,
|
callback?: () => void,
|
||||||
) {
|
) {
|
||||||
console.log("flushing data", data);
|
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
data = Buffer.from(data, encoding);
|
data = Buffer.from(data, encoding);
|
||||||
}
|
}
|
||||||
|
@ -607,20 +583,9 @@ Object.defineProperties(
|
||||||
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||||
}
|
}
|
||||||
if (data.buffer.byteLength > 0) {
|
if (data.buffer.byteLength > 0) {
|
||||||
console.log("waiting for bodyWriter to be ready", {
|
|
||||||
data: new TextDecoder().decode(data.slice(-20, -1)),
|
|
||||||
});
|
|
||||||
this._bodyWriter.ready.then(() => {
|
this._bodyWriter.ready.then(() => {
|
||||||
console.log("bodyWriter is ready", {
|
|
||||||
desirezedSize: this._bodyWriter.desiredSize,
|
|
||||||
});
|
|
||||||
if (this._bodyWriter.desiredSize > 0) {
|
if (this._bodyWriter.desiredSize > 0) {
|
||||||
this._bodyWriter.write(data).then(() => {
|
this._bodyWriter.write(data).then(() => {
|
||||||
console.log("writing done: ", {
|
|
||||||
last_bytes: new TextDecoder().decode(data.slice(-20, -1)),
|
|
||||||
length: data.length,
|
|
||||||
buffer: this.outputData.length,
|
|
||||||
});
|
|
||||||
callback?.();
|
callback?.();
|
||||||
if (this.outputData.length == 0) {
|
if (this.outputData.length == 0) {
|
||||||
this.emit("finish");
|
this.emit("finish");
|
||||||
|
@ -766,8 +731,6 @@ Object.defineProperties(
|
||||||
|
|
||||||
const { header } = state;
|
const { header } = state;
|
||||||
this._header = header + "\r\n";
|
this._header = header + "\r\n";
|
||||||
// console.log("_headerSent set to false");
|
|
||||||
// this._headerSent = false;
|
|
||||||
|
|
||||||
// Wait until the first body chunk, or close(), is sent to flush,
|
// Wait until the first body chunk, or close(), is sent to flush,
|
||||||
// UNLESS we're sending Expect: 100-continue.
|
// UNLESS we're sending Expect: 100-continue.
|
||||||
|
|
|
@ -398,7 +398,6 @@ class ClientRequest extends OutgoingMessage {
|
||||||
if (typeof optsWithoutSignal.createConnection === "function") {
|
if (typeof optsWithoutSignal.createConnection === "function") {
|
||||||
const oncreate = once((err, socket) => {
|
const oncreate = once((err, socket) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("emitting error", { err });
|
|
||||||
this.emit("error", err);
|
this.emit("error", err);
|
||||||
} else {
|
} else {
|
||||||
this.onSocket(socket);
|
this.onSocket(socket);
|
||||||
|
@ -424,7 +423,6 @@ class ClientRequest extends OutgoingMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
_writeHeader() {
|
_writeHeader() {
|
||||||
console.trace("_writeHeader invoked");
|
|
||||||
const url = this._createUrlStrFromOptions();
|
const url = this._createUrlStrFromOptions();
|
||||||
|
|
||||||
const headers = [];
|
const headers = [];
|
||||||
|
@ -453,11 +451,8 @@ class ClientRequest extends OutgoingMessage {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url);
|
||||||
console.trace("starting conn");
|
|
||||||
let baseConnRid = this.socket.rid;
|
let baseConnRid = this.socket.rid;
|
||||||
console.log("socket:", baseConnRid);
|
|
||||||
if (this._encrypted) {
|
if (this._encrypted) {
|
||||||
console.log("encrypted");
|
|
||||||
[baseConnRid] = op_tls_start({
|
[baseConnRid] = op_tls_start({
|
||||||
rid: this.socket.rid,
|
rid: this.socket.rid,
|
||||||
hostname: parsedUrl.hostname,
|
hostname: parsedUrl.hostname,
|
||||||
|
@ -467,39 +462,18 @@ class ClientRequest extends OutgoingMessage {
|
||||||
}
|
}
|
||||||
let rid;
|
let rid;
|
||||||
let connRid;
|
let connRid;
|
||||||
try {
|
[rid, connRid] = await op_node_http_request_with_conn(
|
||||||
console.log(
|
this.method,
|
||||||
"sending request with conn",
|
url,
|
||||||
this._bodyWriteRid,
|
headers,
|
||||||
baseConnRid,
|
this._bodyWriteRid,
|
||||||
this._encrypted,
|
baseConnRid,
|
||||||
);
|
this._encrypted,
|
||||||
[rid, connRid] = await op_node_http_request_with_conn(
|
)
|
||||||
this.method,
|
await op_node_http_wait_for_connection(connRid);
|
||||||
url,
|
|
||||||
headers,
|
|
||||||
this._bodyWriteRid,
|
|
||||||
baseConnRid,
|
|
||||||
this._encrypted,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("error from request with conn", error);
|
|
||||||
}
|
|
||||||
// Emit request ready to let the request body to be written.
|
// Emit request ready to let the request body to be written.
|
||||||
try {
|
|
||||||
await op_node_http_wait_for_connection(connRid);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("error from wait for connection", error);
|
|
||||||
}
|
|
||||||
console.log("request ready");
|
|
||||||
this.emit("requestReady");
|
this.emit("requestReady");
|
||||||
let res;
|
const res = await op_node_http_await_response(rid);
|
||||||
try {
|
|
||||||
res = await op_node_http_await_response(rid);
|
|
||||||
console.log("response received", { res });
|
|
||||||
} catch (error) {
|
|
||||||
console.log("error from await response", error);
|
|
||||||
}
|
|
||||||
const incoming = new IncomingMessageForClient(this.socket);
|
const incoming = new IncomingMessageForClient(this.socket);
|
||||||
incoming.req = this;
|
incoming.req = this;
|
||||||
this.res = incoming;
|
this.res = incoming;
|
||||||
|
@ -538,43 +512,26 @@ class ClientRequest extends OutgoingMessage {
|
||||||
if (this.method === "CONNECT") {
|
if (this.method === "CONNECT") {
|
||||||
throw new Error("not implemented CONNECT");
|
throw new Error("not implemented CONNECT");
|
||||||
}
|
}
|
||||||
let upgradeRid;
|
const upgradeRid = await op_node_http_fetch_response_upgrade(
|
||||||
try {
|
res.responseRid,
|
||||||
upgradeRid = await op_node_http_fetch_response_upgrade(
|
);
|
||||||
res.responseRid,
|
const conn = new TcpConn(
|
||||||
);
|
upgradeRid,
|
||||||
} catch (error) {
|
{
|
||||||
console.log("error from fetch response upgrade", error);
|
transport: "tcp",
|
||||||
}
|
hostname: res.remoteAddrIp,
|
||||||
assert(typeof res.remoteAddrIp !== "undefined");
|
port: res.remoteAddrIp,
|
||||||
assert(typeof res.remoteAddrIp !== "undefined");
|
},
|
||||||
let conn;
|
// TODO(bartlomieju): figure out actual values
|
||||||
try {
|
{
|
||||||
conn = new TcpConn(
|
transport: "tcp",
|
||||||
upgradeRid,
|
hostname: "127.0.0.1",
|
||||||
{
|
port: 80,
|
||||||
transport: "tcp",
|
},
|
||||||
hostname: res.remoteAddrIp,
|
);
|
||||||
port: res.remoteAddrIp,
|
const socket = new Socket({
|
||||||
},
|
handle: new TCP(constants.SERVER, conn),
|
||||||
// TODO(bartlomieju): figure out actual values
|
});
|
||||||
{
|
|
||||||
transport: "tcp",
|
|
||||||
hostname: "127.0.0.1",
|
|
||||||
port: 80,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.log("error from new connectin");
|
|
||||||
}
|
|
||||||
let socket;
|
|
||||||
try {
|
|
||||||
socket = new Socket({
|
|
||||||
handle: new TCP(constants.SERVER, conn),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log("error from new Socket", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.upgradeOrConnect = true;
|
this.upgradeOrConnect = true;
|
||||||
|
|
||||||
|
@ -604,10 +561,8 @@ class ClientRequest extends OutgoingMessage {
|
||||||
// Node.js seems ignoring this error
|
// Node.js seems ignoring this error
|
||||||
} else if (err.message.includes("The signal has been aborted")) {
|
} else if (err.message.includes("The signal has been aborted")) {
|
||||||
// Remap this error
|
// Remap this error
|
||||||
console.log("emitting socket hung up error");
|
|
||||||
this.emit("error", connResetException("socket hang up"));
|
this.emit("error", connResetException("socket hang up"));
|
||||||
} else {
|
} else {
|
||||||
console.log("emitting error event", err);
|
|
||||||
this.emit("error", err);
|
this.emit("error", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,7 +596,6 @@ class ClientRequest extends OutgoingMessage {
|
||||||
err = new connResetException("socket hang up");
|
err = new connResetException("socket hang up");
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("error event", err);
|
|
||||||
emitErrorEvent(req, err);
|
emitErrorEvent(req, err);
|
||||||
}
|
}
|
||||||
req._closed = true;
|
req._closed = true;
|
||||||
|
|
Loading…
Reference in a new issue