Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response header customization #3630

Closed
1 of 2 tasks
FlorianAgsten opened this issue Aug 8, 2020 · 1 comment
Closed
1 of 2 tasks

response header customization #3630

FlorianAgsten opened this issue Aug 8, 2020 · 1 comment
Milestone

Comments

@FlorianAgsten
Copy link

FlorianAgsten commented Aug 8, 2020

You want to:

  • report a bug
  • request a feature

Current behaviour

The socket.io-implementation is removing every listener on the requests and therefore any kind of adjustment on the headers (e.g. from the surrounding express-server) is not possible.
If it is necessary to add a header to the socket.io-calls (e.g. 'X-Content-Type-Options'), a manipulation of the used socket.io-lib is inevitable.

Expected behaviour

It should be possible to add/adjust headers to the socket.io-server, which are used for all the responses created by the socket.io-server.

Setup

  • OS: Ubuntu
  • browser: Chrome, Firefox
  • socket.io version: 2.3.0
darrachequesne added a commit to socketio/engine.io that referenced this issue Apr 30, 2021
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

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:

- #557
- socketio/socket.io#3630
darrachequesne added a commit to socketio/engine.io that referenced this issue Apr 30, 2021
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:

- #557
- socketio/socket.io#3630
@darrachequesne
Copy link
Member

This was implemented in [email protected]:

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

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

Reference:

Thanks for the suggestion 👍

@darrachequesne darrachequesne added this to the 4.1.0 milestone Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants