Skip to content

Commit 029f478

Browse files
committedSep 25, 2020
feat: remove Server#set() method
This method was kept for backward-compatibility with pre-1.0 versions.
1 parent 424a473 commit 029f478

File tree

2 files changed

+0
-161
lines changed

2 files changed

+0
-161
lines changed
 

‎lib/index.ts

-37
Original file line numberDiff line numberDiff line change
@@ -142,32 +142,6 @@ class Server extends EventEmitter {
142142
return this;
143143
}
144144

145-
/**
146-
* Backwards compatibility.
147-
*/
148-
public set(key, val) {
149-
if ("authorization" == key && val) {
150-
// @ts-ignore
151-
this.use(function(socket, next) {
152-
val(socket.request, function(err, authorized) {
153-
if (err) return next(new Error(err));
154-
if (!authorized) return next(new Error("Not authorized"));
155-
next();
156-
});
157-
});
158-
} else if ("origins" == key && val) {
159-
this.origins(val);
160-
} else if ("resource" == key) {
161-
this.path(val);
162-
} else if (oldSettings[key] && this.eio[oldSettings[key]]) {
163-
this.eio[oldSettings[key]] = val;
164-
} else {
165-
console.error("Option %s is not valid. Please refer to the README.", key);
166-
}
167-
168-
return this;
169-
}
170-
171145
/**
172146
* Executes the middleware for an incoming namespace not already created on the server.
173147
*
@@ -535,17 +509,6 @@ class Server extends EventEmitter {
535509
}
536510
}
537511

538-
/**
539-
* Old settings for backwards compatibility
540-
*/
541-
542-
const oldSettings = {
543-
transports: "transports",
544-
"heartbeat timeout": "pingTimeout",
545-
"heartbeat interval": "pingInterval",
546-
"destroy buffer size": "maxHttpBufferSize"
547-
};
548-
549512
/**
550513
* Expose main namespace (/).
551514
*/

‎test/socket.io.js

-124
Original file line numberDiff line numberDiff line change
@@ -29,130 +29,6 @@ describe("socket.io", () => {
2929
expect(version).to.be(require("socket.io-client/package").version);
3030
});
3131

32-
describe("set", () => {
33-
it("should be able to set ping timeout to engine.io", () => {
34-
const srv = io(http());
35-
srv.set("heartbeat timeout", 10);
36-
expect(srv.eio.pingTimeout).to.be(10);
37-
});
38-
39-
it("should be able to set ping interval to engine.io", () => {
40-
const srv = io(http());
41-
srv.set("heartbeat interval", 10);
42-
expect(srv.eio.pingInterval).to.be(10);
43-
});
44-
45-
it("should be able to set transports to engine.io", () => {
46-
const srv = io(http());
47-
srv.set("transports", ["polling"]);
48-
expect(srv.eio.transports).to.eql(["polling"]);
49-
});
50-
51-
it("should be able to set maxHttpBufferSize to engine.io", () => {
52-
const srv = io(http());
53-
srv.set("destroy buffer size", 10);
54-
expect(srv.eio.maxHttpBufferSize).to.eql(10);
55-
});
56-
57-
it("should be able to set path with setting resource", done => {
58-
const eio = io();
59-
const srv = http();
60-
61-
eio.set("resource", "/random");
62-
eio.attach(srv);
63-
64-
// Check that the server is accessible through the specified path
65-
request(srv)
66-
.get("/random/socket.io.js")
67-
.buffer(true)
68-
.end((err, res) => {
69-
if (err) return done(err);
70-
done();
71-
});
72-
});
73-
74-
it("should be able to set origins to engine.io", () => {
75-
const srv = io(http());
76-
srv.set("origins", "http://hostname.com:*");
77-
expect(srv.origins()).to.be("http://hostname.com:*");
78-
});
79-
80-
it("should be able to set authorization and send error packet", done => {
81-
const httpSrv = http();
82-
const srv = io(httpSrv);
83-
srv.set("authorization", (o, f) => {
84-
f(null, false);
85-
});
86-
87-
const socket = client(httpSrv);
88-
socket.on("connect", () => {
89-
expect().fail();
90-
});
91-
socket.on("error", err => {
92-
expect(err).to.be("Not authorized");
93-
done();
94-
});
95-
});
96-
97-
it("should be able to set authorization and succeed", done => {
98-
const httpSrv = http();
99-
const srv = io(httpSrv);
100-
srv.set("authorization", (o, f) => {
101-
f(null, true);
102-
});
103-
104-
srv.on("connection", s => {
105-
s.on("yoyo", data => {
106-
expect(data).to.be("data");
107-
done();
108-
});
109-
});
110-
111-
const socket = client(httpSrv);
112-
socket.on("connect", () => {
113-
socket.emit("yoyo", "data");
114-
});
115-
116-
socket.on("error", err => {
117-
expect().fail();
118-
});
119-
});
120-
121-
it("should set the handshake BC object", done => {
122-
const httpSrv = http();
123-
const srv = io(httpSrv);
124-
125-
srv.on("connection", s => {
126-
expect(s.handshake).to.not.be(undefined);
127-
128-
// Headers set and has some valid properties
129-
expect(s.handshake.headers).to.be.an("object");
130-
expect(s.handshake.headers["user-agent"]).to.be("node-XMLHttpRequest");
131-
132-
// Time set and is valid looking string
133-
expect(s.handshake.time).to.be.a("string");
134-
expect(s.handshake.time.split(" ").length > 0); // Is "multipart" string representation
135-
136-
// Address, xdomain, secure, issued and url set
137-
expect(s.handshake.address).to.contain("127.0.0.1");
138-
expect(s.handshake.xdomain).to.be.a("boolean");
139-
expect(s.handshake.secure).to.be.a("boolean");
140-
expect(s.handshake.issued).to.be.a("number");
141-
expect(s.handshake.url).to.be.a("string");
142-
143-
// Query set and has some right properties
144-
expect(s.handshake.query).to.be.an("object");
145-
expect(s.handshake.query.EIO).to.not.be(undefined);
146-
expect(s.handshake.query.transport).to.not.be(undefined);
147-
expect(s.handshake.query.t).to.not.be(undefined);
148-
149-
done();
150-
});
151-
152-
const socket = client(httpSrv);
153-
});
154-
});
155-
15632
describe("server attachment", () => {
15733
describe("http.Server", () => {
15834
const clientVersion = require("socket.io-client/package").version;

0 commit comments

Comments
 (0)
Please sign in to comment.