-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Expose request headers #2073
Comments
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ port: 8080 });
wss.on('connection', function (websocket, request) {
console.log(request.headers);
}); or using import { createServer } from 'http';
import { WebSocketServer } from 'ws';
const server = createServer();
const wss = new WebSocketServer({ noServer: true });
wss.on('connection', function (websocket, request) {
// ...
});
server.on('upgrade', function (request, socket, head) {
console.log(request.headers);
wss.handleUpgrade(request, socket, head, function done(websocket) {
wss.emit('connection', websocket, request);
});
});
server.listen(8080); |
Thanks for the quick response! Apologies, I realize now that I've made my feature request ambiguous. I meant with reference to the WebSocket client, not the server. That is, the ability to see the actual complete request headers that it sends. |
You can use const ws = new WebSocket(url);
ws._req.getHeaders(); but I would rather not turn it into an officially supported API. |
Fair enough. I appreciate the fast responses. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Description
I'd like to be able to get the verbatim request headers for diagnostic purposes, but today I don't see anywhere in the API surface where this can be intercepted. It would be very useful to have an additional API or event for this.
ws version
No response
Node.js Version
v16.14.2
System
Expected result
N/A
Actual result
N/A
Attachments
No response
The text was updated successfully, but these errors were encountered: