Skip to content

Commit

Permalink
fix connect, add alpn test
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Jul 3, 2023
1 parent 8f3249c commit fa0b07d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
15 changes: 5 additions & 10 deletions src/js/node/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,11 @@ const TLSSocket = (function (InternalTLSSocket) {
}

[buntls](port, host) {
var { servername } = this;
if (servername) {
return {
ALPNProtocols: this.ALPNProtocols,
serverName: typeof servername === "string" ? servername : host,
...this.#secureContext,
};
}

return true;
return {
ALPNProtocols: this.ALPNProtocols,
serverName: this.servername || host || "localhost",
...this.#secureContext,
};
}
},
);
Expand Down
13 changes: 5 additions & 8 deletions src/js/out/modules/node/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,11 @@ var createServer = function(options, connectionListener) {
return this[bunSocketInternal]?.alpnProtocol;
}
[buntls](port, host2) {
var { servername } = this;
if (servername)
return {
ALPNProtocols: this.ALPNProtocols,
serverName: typeof servername === "string" ? servername : host2,
...this.#secureContext
};
return !0;
return {
ALPNProtocols: this.ALPNProtocols,
serverName: this.servername || host2 || "localhost",
...this.#secureContext
};
}
});

Expand Down
32 changes: 32 additions & 0 deletions test/js/node/tls/node-tls-connect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { TLSSocket, connect } from "tls";

it("should work with alpnProtocols", done => {
try {
let socket: TLSSocket | null = connect({
ALPNProtocols: ["http/1.1"],
host: "bun.sh",
servername: "bun.sh",
port: 443,
rejectUnauthorized: false,
});

const timeout = setTimeout(() => {
socket?.end();
done("timeout");
}, 3000);

socket.on("error", err => {
clearTimeout(timeout);
done(err);
});

socket.on("secureConnect", () => {
clearTimeout(timeout);
done(socket?.alpnProtocol === "http/1.1" ? undefined : "alpnProtocol is not http/1.1");
socket?.end();
socket = null;
});
} catch (err) {
done(err);
}
});

0 comments on commit fa0b07d

Please sign in to comment.