fix(eio-client): properly handle port option (#5241)

Passing { port: "443" } would include the port in the URL (":443").
This commit is contained in:
MiaoWoo
2024-11-27 11:45:16 +08:00
committed by Damien Arrachequesne
parent 6f9b198bc8
commit 1da9cddeab
2 changed files with 27 additions and 1 deletions

View File

@@ -192,7 +192,7 @@ export abstract class Transport extends Emitter<
private _port() {
if (
this.opts.port &&
((this.opts.secure && Number(this.opts.port !== 443)) ||
((this.opts.secure && Number(this.opts.port) !== 443) ||
(!this.opts.secure && Number(this.opts.port) !== 80))
) {
return ":" + this.opts.port;

View File

@@ -116,6 +116,32 @@ describe("Transport", () => {
expect(polling.uri()).to.contain("https://localhost/engine.io?sid=test");
});
it("should generate an https uri w/o a port (string)", () => {
const polling = new eio.transports.polling({
path: "/engine.io",
hostname: "localhost",
secure: true,
query: { sid: "test" },
port: "443",
timestampRequests: false,
});
expect(polling.uri()).to.contain("https://localhost/engine.io?sid=test");
});
it("should generate an https uri with a port", () => {
const polling = new eio.transports.polling({
path: "/engine.io",
hostname: "localhost",
secure: true,
query: { sid: "test" },
port: 8443,
timestampRequests: false,
});
expect(polling.uri()).to.contain(
"https://localhost:8443/engine.io?sid=test",
);
});
it("should generate a timestamped uri", () => {
const polling = new eio.transports.polling({
path: "/engine.io",