Commit Graph

1070 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
7096e98a02 feat: add a "connection_error" event
The "connection_error" event will be emitted when one of the following
errors occurs:

- Transport unknown
- Session ID unknown
- Bad handshake method
- Bad request
- Forbidden
- Unsupported protocol version

Syntax:

```js
server.on("connection_error", (err) => {
  console.log(err.req);		// the request object
  console.log(err.code);	// the error code, for example 1
  console.log(err.message);	// the error message, for example "Session ID unknown"
  console.log(err.context);     // some additional error context
});
```

Related:

- https://github.com/socketio/socket.io/issues/3819
- https://github.com/socketio/engine.io/issues/576
2021-04-30 13:04:28 +02:00
Damien Arrachequesne
887ba06536 chore(release): 5.0.0
Diff: https://github.com/socketio/engine.io/compare/4.1.1...5.0.0
2021-03-10 10:20:02 +01:00
Damien Arrachequesne
edb734316f feat: remove dynamic require() with wsEngine
This change is necessary to get rid of:

> Critical dependency: the request of a dependency is an expression

when bundling the server with webpack.

BREAKING CHANGE: the syntax of the "wsEngine" option is updated

Before:

```js
const eioServer = require("engine.io")(httpServer, {
  wsEngine: "eiows"
});
```

After:

```js
const eioServer = require("engine.io")(httpServer, {
  wsEngine: require("eiows").Server
});
```

Related: https://github.com/socketio/engine.io/issues/609
2021-03-09 08:30:05 +01:00
Simone Mazzoni
868d89111d fix: set default protocol version to 3 (#616)
socket.io-client-swift libs version <=15.2.0, which uses protocol
version 3, do not explicitly add the EIO query parameter at transport
initialization. This omission leads the server to treat the client as
a client that supports the protocol version 4, previously set as
default, which is not correct for those versions of the client lib.

From socket.io-client-swift version v16.0.0 the EIO query parameter is
explicitly passed to specify the protocol version supported, but since
the allowEIO3 parameter aims to make the server compatible with
previous versions which in most of the cases are already used in
production and not easily upgradable, it makes more sense to default
the EIO version to 3 if not explicitly set by the client since the
newer client versions pass the EIO protocol version in query
parameters.

Related: https://github.com/socketio/socket.io/issues/3794
2021-03-09 08:23:36 +01:00
Damien Arrachequesne
5a7fa132c4 feat: increase the default value of pingTimeout
This value was updated from 60000 to 5000 in [1], included in
`engine.io@3.2.0` (Feb 2018).

The reasoning back then:

Some users experienced long delays between disconnection on the
server-side and on the client-side. The "disconnect" event would take a
long time to fire in the browser, probably due to a timer being
delayed. Hence the change.

That being said, the current value (5s) now causes unexpected
disconnections when a big payload is sent over a slow network, because
it prevents the ping-pong packets from being exchanged between the
client and the server. This can also happen when a synchronous task
blocks the server for more than 5 seconds.

The new value (20s) thus seems like a good balance between quick
disconnection detection and tolerance to various delays.

Note: pingInterval + pingTimeout is still below the threshold of React
Native, which complains if a timer is set with a delay of more than 1
minute.

[1]: 65b1ad1b8a

Related:

- https://github.com/socketio/socket.io/issues/2770
- https://github.com/socketio/socket.io/issues/2769
- https://github.com/socketio/socket.io/issues/3054
- https://github.com/socketio/socket.io/issues/3376
2021-03-02 08:49:58 +01:00
Damien Arrachequesne
9534355b89 chore(release): 4.1.1
Diff: https://github.com/socketio/engine.io/compare/4.1.0...4.1.1
2021-02-02 10:51:04 +01:00
Damien Arrachequesne
ae840fa8ed chore: point towards the master branch for the CI badge
Reference: https://docs.github.com/en/actions/managing-workflow-runs/adding-a-workflow-status-badge#using-the-branch-parameter
2021-02-02 10:49:24 +01: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
e5b307c16d chore(release): 4.1.0
Diff: https://github.com/socketio/engine.io/compare/4.0.6...4.1.0
2021-01-14 01:47:14 +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
9b621523ef chore(release): 4.0.6
Diff: https://github.com/socketio/engine.io/compare/4.0.5...4.0.6
2021-01-04 23:27:25 +01:00
Damien Arrachequesne
5a91253f21 chore: bump ws and debug versions 2021-01-04 23:03:49 +01:00
Damien Arrachequesne
fffa0a3fb7 chore: update GitHub issue templates 2020-12-30 10:28:34 +01:00
Marko Žarković
cec27502f5 fix: correctly pass the options when using the Server constructor (#610)
Fixes https://github.com/socketio/engine.io/issues/580
2020-12-30 10:04:47 +01:00
Damien Arrachequesne
04ea3585e8 docs(changelog): include changelog for release 3.5.0
Merged from the 3.5.x branch.
2020-12-30 10:01:18 +01:00
Damien Arrachequesne
e7115b88bb chore(release): 4.0.5
Diff: https://github.com/socketio/engine.io/compare/4.0.4...4.0.5
2020-12-07 11:26:35 +01:00
Damien Arrachequesne
f5efa1e02a refactor: use ES6 syntax for the tests 2020-12-07 10:57:28 +01:00
Damien Arrachequesne
312bd356c7 ci: migrate to GitHub Actions
Due to the recent changes to the Travis CI platform (see [1]), we will
now use GitHub Actions to run the tests.

Reference: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs

[1]: https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing
2020-12-07 10:52:08 +01:00
Damien Arrachequesne
c2981c6040 chore(release): 4.0.4
Diff: https://github.com/socketio/engine.io/compare/4.0.3...4.0.4
2020-11-17 22:51:56 +01:00
Damien Arrachequesne
67ca12c533 chore(release): 4.0.3
Diff: https://github.com/socketio/engine.io/compare/4.0.2...4.0.3
2020-11-17 10:06:52 +01:00
Damien Arrachequesne
9ddccf398e chore: bump engine.io-client 2020-11-09 10:11:20 +01:00
Damien Arrachequesne
16fd658274 chore(release): 4.0.2
Diff: https://github.com/socketio/engine.io/compare/4.0.1...4.0.2
2020-11-09 10:03:04 +01:00
Andrew Stoker
17b8c2f199 fix: add extension in the package.json main entry (#608)
The `main` entry for the `package.json` file is for defining the entry
point. The entry is currently missing the required `.js` extension,
this PR brings it back.
2020-11-08 02:00:54 +01:00
Damien Arrachequesne
3284208a6d chore: bump engine.io-client 2020-10-22 00:36:45 +02:00
Damien Arrachequesne
58943c3b30 chore(release): 4.0.1
Diff: https://github.com/socketio/engine.io/compare/4.0.0...4.0.1
2020-10-22 00:30:51 +02:00
Damien Arrachequesne
c099338e04 refactor: remove binary handling for the polling transport
Since Engine.IO v4, the binary payloads are always encoded as base64
with the polling transport.

See https://github.com/socketio/engine.io-protocol#difference-between-v3-and-v4
2020-10-22 00:12:05 +02:00
Damien Arrachequesne
fe093bae1a fix: do not overwrite CORS headers upon error
The Access-Control-Allow-xxx headers added by the cors middleware were
overwritten when sending an error response.

Those lines should have been removed in [1].

[1]: 61b949259e

Related: https://github.com/socketio/engine.io/issues/605
2020-10-22 00:11:06 +02:00
Damien Arrachequesne
f9c0e74b14 chore: bump eiows to 3.3.2
The CI was failing with Node.js 14.13.0.
2020-10-05 01:04:17 +02:00
Damien Arrachequesne
a05379b1e8 test: use eiows
The eiows package is the published version of [1], which is a fork of
uws (a performant WebSocket server written in C++ with bindings for
Node.js).

[1] https://github.com/mmdevries/uws
2020-09-14 22:20:36 +02:00
Damien Arrachequesne
428b4f5200 docs: update links to other repositories 2020-09-14 22:04:49 +02:00
Damien Arrachequesne
ec83022ef4 docs: update examples with ES6 syntax 2020-09-14 22:00:40 +02:00
Damien Arrachequesne
609223959c docs: update latency example
The enchilada module fails to bundle the Engine.IO client, so we'll
just import the published bundle.

The exception seems to come from debug:

> Spread must be the final element of an element list
2020-09-11 02:40:28 +02:00
Damien Arrachequesne
70b1c36be1 chore(release): 4.0.0
Diff: https://github.com/socketio/engine.io/compare/v4.0.0-alpha.1...4.0.0
Full diff: https://github.com/socketio/engine.io/compare/3.4.0...4.0.0
2020-09-11 00:59:57 +02:00
Damien Arrachequesne
9df38d57fb docs: update the list of supported engines
As Node.js 8 is now EOL.
2020-09-10 15:52:32 +02:00
Damien Arrachequesne
078527a384 feat: disable perMessageDeflate by default
The WebSocket permessage-deflate extension, while useful is some cases,
adds some extra memory overhead for each WebSocket connection, and
results in huge memory usage in production deployments.

It will now be disabled by default.
2020-09-10 15:46:04 +02:00
Damien Arrachequesne
54c67978d5 docs: update the default value of maxHttpBufferSize
Following 734f9d1268
2020-09-10 15:22:43 +02:00
Damien Arrachequesne
1916d3ae62 test: remove Node.js 8 from the test matrix
Reference: https://github.com/nodejs/Release
2020-09-10 15:20:00 +02:00
Damien Arrachequesne
14ca7a1cfc chore: restore package-lock.json file
The package-lock.json file was removed in the previous commit, in order
to sync the client version when upgrading the parser (and make the
tests pass).
2020-09-09 02:09:44 +02:00
Damien Arrachequesne
ed29e5955d chore: bump engine.io-parser version
See also: https://github.com/socketio/engine.io-protocol#difference-between-v3-and-v4

Release: https://github.com/socketio/engine.io-parser/releases/tag/4.0.0
Diff: https://github.com/socketio/engine.io-parser/compare/2.2.0...4.0.0
2020-09-09 00:00:25 +02:00
Damien Arrachequesne
03b49674e6 chore: bump cookie version
Release: https://github.com/jshttp/cookie/releases/tag/v0.4.0
Diff: https://github.com/jshttp/cookie/compare/v0.3.1...v0.4.1
2020-09-08 02:47:18 +02:00
Damien Arrachequesne
09708eb307 docs(changelog): include changelog for release 3.4.2
Merged from the 3.4.x branch.
2020-06-04 16:23:05 +02:00
Damien Arrachequesne
82cdca23ba fix: remove implicit require of uws
So that bundlers like webpack do not try to include it in the build.

As a side-effect, any implementation which matches the API of the ws
module can now be used.

Before that change, you had to explicitly exclude uws:

```
// webpack.config.js
module.exports = {
  // ...
  externals: {
     uws: 'uws'
  }
};
```

Related: https://github.com/socketio/engine.io/issues/575
2020-06-04 14:24:42 +02:00
Damien Arrachequesne
94623c8f8b docs(changelog): include changelog for release 3.4.1
Merged from the 3.4.x branch.
2020-04-17 14:57:35 +02:00
Damien Arrachequesne
dcdbccb3dd fix: ignore errors when forcefully closing the socket (#601)
In order to catch the following errors:

```
events.js:288
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:154:25)
    at writeGeneric (internal/stream_base_commons.js:145:3)
    at Socket._writeGeneric (net.js:780:11)
    at Socket._write (net.js:792:8)
    at doWrite (_stream_writable.js:441:12)
    at writeOrBuffer (_stream_writable.js:425:5)
    at Socket.Writable.write (_stream_writable.js:316:11)
    at abortConnection (<myproject>/node_modules/engine.io/lib/server.js:506:12)
    at <myproject>/node_modules/engine.io/lib/server.js:353:7
    at Server.verify (<myproject>/node_modules/engine.io/lib/server.js:158:14)
    at Server.handleUpgrade (<myproject>/node_modules/engine.io/lib/server.js:351:8)
```

Closes https://github.com/socketio/engine.io/issues/596, https://github.com/socketio/engine.io/pull/598
2020-04-15 11:42:31 +02:00
Damien Arrachequesne
71ece3ebf6 chore(release): 4.0.0-alpha.1 2020-02-12 08:33:47 +01:00
Damien Arrachequesne
b27215dcee chore(release): 4.0.0-alpha.0 2020-02-12 07:50:43 +01:00
Damien Arrachequesne
734f9d1268 feat: decrease the default value of maxHttpBufferSize
This change reduces the default value from 100 mb to a more sane 1 mb.

This helps protect the server against denial of service attacks by
malicious clients sending huge amounts of data.
2020-02-11 07:59:13 +01:00
Damien Arrachequesne
61b949259e feat: use the cors module to handle cross-origin requests
We'll now rely on the standard cors module (https://github.com/expressjs/cors),
instead of the custom implementation that is error-prone and not
really user-friendly.

Breaking change: the handlePreflightRequest option is removed by the
change.

Before:

```
new Server({
  handlePreflightRequest: (req, res) => {
    res.writeHead(200, {
      "Access-Control-Allow-Origin": 'https://example.com',
      "Access-Control-Allow-Methods": 'GET',
      "Access-Control-Allow-Headers": 'Authorization',
      "Access-Control-Allow-Credentials": true
    });
    res.end();
  }
})
```

After:

```
new Server({
  cors: {
    origin: "https://example.com",
    methods: ["GET"],
    allowedHeaders: ["Authorization"],
    credentials: true
  }
})
```
2020-02-11 07:54:25 +01:00