Skip to content

Commit

Permalink
feat: remove Server#set() method
Browse files Browse the repository at this point in the history
This method was kept for backward-compatibility with pre-1.0 versions.
  • Loading branch information
darrachequesne committed Sep 25, 2020
1 parent 424a473 commit 029f478
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 161 deletions.
37 changes: 0 additions & 37 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,6 @@ class Server extends EventEmitter {
return this;
}

/**
* Backwards compatibility.
*/
public set(key, val) {
if ("authorization" == key && val) {
// @ts-ignore
this.use(function(socket, next) {
val(socket.request, function(err, authorized) {
if (err) return next(new Error(err));
if (!authorized) return next(new Error("Not authorized"));
next();
});
});
} else if ("origins" == key && val) {
this.origins(val);
} else if ("resource" == key) {
this.path(val);
} else if (oldSettings[key] && this.eio[oldSettings[key]]) {
this.eio[oldSettings[key]] = val;
} else {
console.error("Option %s is not valid. Please refer to the README.", key);
}

return this;
}

/**
* Executes the middleware for an incoming namespace not already created on the server.
*
Expand Down Expand Up @@ -535,17 +509,6 @@ class Server extends EventEmitter {
}
}

/**
* Old settings for backwards compatibility
*/

const oldSettings = {
transports: "transports",
"heartbeat timeout": "pingTimeout",
"heartbeat interval": "pingInterval",
"destroy buffer size": "maxHttpBufferSize"
};

/**
* Expose main namespace (/).
*/
Expand Down
124 changes: 0 additions & 124 deletions test/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,130 +29,6 @@ describe("socket.io", () => {
expect(version).to.be(require("socket.io-client/package").version);
});

describe("set", () => {
it("should be able to set ping timeout to engine.io", () => {
const srv = io(http());
srv.set("heartbeat timeout", 10);
expect(srv.eio.pingTimeout).to.be(10);
});

it("should be able to set ping interval to engine.io", () => {
const srv = io(http());
srv.set("heartbeat interval", 10);
expect(srv.eio.pingInterval).to.be(10);
});

it("should be able to set transports to engine.io", () => {
const srv = io(http());
srv.set("transports", ["polling"]);
expect(srv.eio.transports).to.eql(["polling"]);
});

it("should be able to set maxHttpBufferSize to engine.io", () => {
const srv = io(http());
srv.set("destroy buffer size", 10);
expect(srv.eio.maxHttpBufferSize).to.eql(10);
});

it("should be able to set path with setting resource", done => {
const eio = io();
const srv = http();

eio.set("resource", "/random");
eio.attach(srv);

// Check that the server is accessible through the specified path
request(srv)
.get("/random/socket.io.js")
.buffer(true)
.end((err, res) => {
if (err) return done(err);
done();
});
});

it("should be able to set origins to engine.io", () => {
const srv = io(http());
srv.set("origins", "http:https://hostname.com:*");
expect(srv.origins()).to.be("http:https://hostname.com:*");
});

it("should be able to set authorization and send error packet", done => {
const httpSrv = http();
const srv = io(httpSrv);
srv.set("authorization", (o, f) => {
f(null, false);
});

const socket = client(httpSrv);
socket.on("connect", () => {
expect().fail();
});
socket.on("error", err => {
expect(err).to.be("Not authorized");
done();
});
});

it("should be able to set authorization and succeed", done => {
const httpSrv = http();
const srv = io(httpSrv);
srv.set("authorization", (o, f) => {
f(null, true);
});

srv.on("connection", s => {
s.on("yoyo", data => {
expect(data).to.be("data");
done();
});
});

const socket = client(httpSrv);
socket.on("connect", () => {
socket.emit("yoyo", "data");
});

socket.on("error", err => {
expect().fail();
});
});

it("should set the handshake BC object", done => {
const httpSrv = http();
const srv = io(httpSrv);

srv.on("connection", s => {
expect(s.handshake).to.not.be(undefined);

// Headers set and has some valid properties
expect(s.handshake.headers).to.be.an("object");
expect(s.handshake.headers["user-agent"]).to.be("node-XMLHttpRequest");

// Time set and is valid looking string
expect(s.handshake.time).to.be.a("string");
expect(s.handshake.time.split(" ").length > 0); // Is "multipart" string representation

// Address, xdomain, secure, issued and url set
expect(s.handshake.address).to.contain("127.0.0.1");
expect(s.handshake.xdomain).to.be.a("boolean");
expect(s.handshake.secure).to.be.a("boolean");
expect(s.handshake.issued).to.be.a("number");
expect(s.handshake.url).to.be.a("string");

// Query set and has some right properties
expect(s.handshake.query).to.be.an("object");
expect(s.handshake.query.EIO).to.not.be(undefined);
expect(s.handshake.query.transport).to.not.be(undefined);
expect(s.handshake.query.t).to.not.be(undefined);

done();
});

const socket = client(httpSrv);
});
});

describe("server attachment", () => {
describe("http.Server", () => {
const clientVersion = require("socket.io-client/package").version;
Expand Down

0 comments on commit 029f478

Please sign in to comment.