Commit Graph

114 Commits

Author SHA1 Message Date
Damien Arrachequesne
4c0aa73e06 refactor: remove "self" references 2021-04-30 14:38:31 +02:00
Damien Arrachequesne
252754353a feat: add the "initial_headers" and "headers" events
Those events will be emitted before the response headers are written to
the socket:

- "initial_headers": on the first request of the connection
- "headers": on all requests (HTTP long-polling and WebSocket upgrade)

Syntax:

```js

server.on("initial_headers", (headers, req) => {
  headers["test"] = "123";
  headers["set-cookie"] = "mycookie=456";
});

server.on("headers", (headers, req) => {
  headers["test"] = "789";
});
```

Related:

- https://github.com/socketio/engine.io/issues/557
- https://github.com/socketio/socket.io/issues/3630
2021-04-30 14:38:11 +02:00
Damien Arrachequesne
ff2b8aba48 fix: do not reset the ping timer after upgrade
There was two issues with this behavior:

- v3 clients (with allowEIO3: true) were also receiving a "ping" after
a successful upgrade, which is incorrect (in v3, it's the client that
sends the "ping", and the server answers with a "pong")

- the ping timer is not reset after upgrade on the client-side, so an
upgrade which took longer than the `pingTimeout` duration could lead to
a "ping timeout" error on the client-side

I think the latter issue is present since the initial implementation.

Related: https://github.com/socketio/socket.io-client-swift/pull/1309#issuecomment-768475704
2021-02-02 10:48:02 +01:00
Damien Arrachequesne
663d326d18 feat: add support for v3.x clients
In order to ease the migration to Socket.IO v3, the Engine.IO server
can now communicate with v3.x clients.

```js
const eioServer = require("engine.io")(httpServer, {
  allowEIO3: true // false by default
});
```

If `allowEIO3` is false, the v3.x clients will now receive an HTTP 400
response ("Unsupported protocol version").

Note: the code of the v3 parser has been imported from [1] and
browser-related dependencies were removed.

[1]: https://github.com/socketio/engine.io-parser/tree/2.2.1

Related:

- https://github.com/socketio/engine.io-protocol/issues/35
- https://github.com/socketio/socket.io-protocol/issues/21
2021-01-14 01:44:52 +01:00
Damien Arrachequesne
bafe684a19 refactor: refactor the handling of the options 2020-02-10 12:07:41 +01:00
Damien Arrachequesne
31ff87593f feat: reverse the ping-pong mechanism
The ping packets will now be sent by the server, because the timers set
in the browsers are not reliable enough. We suspect that a lot of
timeout problems came from timers being delayed on the client-side.

Breaking change: v3.x clients will not be able to connect anymore (they
will send a ping packet and timeout while waiting for a pong packet).

Related: https://github.com/socketio/engine.io/issues/312
2020-02-04 12:31:44 +01:00
Damien Arrachequesne
33564b2391 refactor: use prettier to format code 2020-01-14 21:58:38 +01:00
Damien Arrachequesne
da93fb6ef3 refactor: migrate to ES6 syntax 2020-01-12 22:47:18 +01:00
Damien Arrachequesne
49362abcd0 [fix] Fix undefined remoteAddress when using uws (#533)
Fixes https://github.com/socketio/socket.io/issues/2982
2017-10-11 07:29:52 +02:00
Damien Arrachequesne
fd20b91208 [test] Use npm scripts instead of gulp (#530) 2017-09-01 14:21:57 +02:00
Damien Arrachequesne
274efa120e [feature] Add an initialPacket option (#471) 2017-01-22 07:51:27 +01:00
Konstantin Zolotarev
a3496ed6eb [fix] Discard packets when socket is closed (#469) 2017-01-05 21:01:37 +01:00
Damien Arrachequesne
cd2ff466fc [fix] Only add defined callbacks to the stack (#447)
Before that commit, undefined callbacks were also added to the array,
which could lead to 'Maximum call stack size exceeded' error when
flush() method was called.

Fixes #399
2016-11-21 22:41:47 +01:00
Diga Widyaprana
7cbdd5e5d9 [style] Add ESlint (#385) 2016-10-31 02:40:58 +01:00
nkzawa
941a6ebf52 discard transport on server close 2016-01-21 20:02:54 +09:00
Luigi Pinca
cd97c7f412 polling: don't set the closeTimeoutTimer if the transport is upgraded 2016-01-17 20:19:03 +01:00
nkzawa
1472a79884 remove the compress option from control packets 2015-12-01 14:28:33 +09:00
nkzawa
5092c4fc95 don't compress control packets 2015-11-29 23:27:08 +09:00
nkzawa
02f9ed8173 remove listeners upon clearTransport 2015-09-30 05:26:51 +09:00
nkzawa
66d85e4a5c add tests for closing transports 2015-09-09 03:55:32 +09:00
nkzawa
4bce72c160 call onClose and add close timeout on polling transport 2015-09-09 03:55:10 +09:00
nkzawa
deb7ae40a4 fix sockets can stay open when upgrade failed 2015-08-29 03:48:05 +09:00
Guillermo Rauch
90d3286dad Merge pull request #336 from apeace/bug/socketio-1910
Fixes socket.io#1910 by calling transport.close() on ping timeout
2015-08-27 13:20:50 -07:00
nkzawa
5efbf46626 ensure sockets are closed on error 2015-08-21 03:37:49 +09:00
Andrew Peace
8e1f063c54 Fixes socket.io#1910 by calling transport.close() on ping timeout 2015-08-06 15:43:00 -04:00
Naoyuki Kanezawa
d11e17c8d7 support compression 2015-01-06 02:11:39 +09:00
Luigi Pinca
e754f7eb23 socket: flush the write buffer before closing the socket (fixes #293) 2014-10-25 22:04:16 +02:00
Luigi Pinca
00caf543b8 socket: allow upgrades if the socket is still in closing state
Fixes #284, courtesy of @3rd-Eden
2014-09-26 16:01:11 +02:00
Tony Kovanen
15afd3e2c3 Cache remote address in handshake since it might be lost later. 2014-07-19 04:47:38 +03:00
Guillermo Rauch
76628a0d9e socket: removed unneeded clearTimeout (fixes #250) 2014-04-26 10:50:27 -07:00
DimitarChristoff
e4593af733 fixing looping array via for in to normal loop 2014-03-21 11:32:13 +00:00
Guillermo Rauch
9ab3b106d9 socket: restore 0.8 compatibility 2014-02-12 12:40:22 -08:00
binlain
336e05b461 Fix dos by possibly creating many intervals 2014-02-12 22:12:39 +01:00
binlain
4c84571280 Merge pull request #1 from LearnBoost/master
123
2014-02-12 15:28:54 +01:00
Guillermo Rauch
aa0527fe54 Merge pull request #216 from mokesmokes/reqfix
fix Socket.request for upgraded sockets
2014-02-03 07:25:54 -08:00
Mark Mokryn
25e03c8351 Socket.request a simple property 2014-02-03 17:20:32 +02:00
Mark Mokryn
3b8d7863b8 Socket.request made a nonwritable Socket property set in constructor 2014-02-03 13:32:59 +02:00
Mark Mokryn
c8ddbf8e1c Emit upgrade event after new transport set 2014-02-02 01:59:09 +02:00
Guillermo Rauch
267001cb58 socket: style 2014-01-18 11:24:48 -08:00
binlain
9e01e245bf Use setImmediate instead of process.nextTick 2013-11-17 03:24:28 +01:00
Mark Mokryn
b4b4887f51 fix GH-198 2013-10-30 17:03:19 +02:00
Guillermo Rauch
d352ccdcda Revert "socket: clear timer after sending one noop packet (fixes #174)"
This reverts commit 752dab4c16.
2013-06-15 16:22:40 -07:00
Guillermo Rauch
752dab4c16 socket: clear timer after sending one noop packet (fixes #174) 2013-05-31 07:22:08 -07:00
Raynos
cb578ad70e clear timers in onClose 2013-05-20 23:37:15 -07:00
Raynos
316c84eef3 Clear all timers on socket close 2013-05-20 22:14:27 -07:00
albertyfwu
300b096000 test writeBuffer isn't cleared onError, removed 'closing' check in .flush() 2013-03-12 20:16:46 -04:00
albertyfwu
89de5f5975 fixed bug89 and added tests: writeBuffer not flushed until nextTick' 2013-03-12 02:59:47 -04:00
Andor Goetzendorff
4ef40991be close socket if upgrade is received and socket.readyState != open 2013-01-30 16:57:44 +01:00
roam
148f654c92 Fixed bugs in previous send callback fix and updated test cases 2013-01-16 17:31:42 +08:00
roam
06b39687eb Fixed send callback test failures 2013-01-16 14:35:56 +08:00