-
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
WebSocket
client is acting differently than ws
module with Node, with the exact same code
#4529
Comments
Also, I forgot to precise it, but using |
Can confirm this issue. import WebSocket from "ws";
function initWs() {
const ws = new WebSocket("wss://remote-auth-gateway.discord.gg/?v=2", {
headers: {
Origin: "https://discord.com",
},
});
ws.addEventListener("open", () => {
console.log("discord client connected!!!");
});
ws.addEventListener("error", (e) => {
console.log(e);
});
ws.onmessage = (e) => {
console.log(e.data);
};
ws.onclose = (e) => {
console.log("Closed:", e.code, e.reason);
};
}
initWs(); Running Node 19 (via ts-node):
Bun:
|
Still happens on Bun v1.0.0 by the way |
Found a way to tackle the issue using import tls from 'node:tls';
import websocket from 'websocket-driver';
const driver = websocket.client('wss://remote-auth-gateway.discord.gg/?v=2');
driver.setHeader('Origin', 'https://discord.com');
const tcp = tls.connect(443, 'remote-auth-gateway.discord.gg');
tcp.pipe(driver.io).pipe(tcp);
tcp.on('connect', function() {
driver.start();
});
driver.on('open', function(event) {
console.log("discord client connected!!!");
})
driver.on('error', function(event) {
console.error(event);
})
driver.on('close', function(event) {
console.log('Closed:', event);
})
driver.messages.on('data', function(message) {
console.log(message);
}); This works! |
Yeah I am facing some issues with |
Made a package to make all this easier, until Bun fixes it themselves :')
import TCPWebSocket from "tcp-websocket";
const ws = new TCPWebSocket("wss://remote-auth-gateway.discord.gg/?v=2", {
headers: {
"Origin": "https://discord.com"
}
});
ws.on("message", (e) => {
console.log(e.data);
})
ws.on("close", (e) => {
console.log("Closed:", e.code, e.reason);
}); |
Still observing this in 1.0.7 and this is preventing us from using Bun in production. |
Still happening after v1.0.15 which is a bummer seeing they fixed so much in the v1.0.15 changelog |
@cirospaciari any idea? |
Yes the issue is that: Origin header gets cased to Could happen with any other header to be honest like the |
any updates on this? |
v1.0.31 and that bug is still there. |
Solved in bun 1.1 :) |
not too sure about that. I tried and the connection still didn't persist for too long 😅 |
Still having issues with the headers casing (it's not applying the case from JS) so it's still bugged for me. (ex: |
Experiencing the same error while using
|
i am working on bun version 1.0.29 in May 2024. I am making a request to the other server from BUN + Elysia, header contain the underscore and also capital case: " |
Hello plssssssss. Anyone can take a coffe and fix this bug ? |
What version of Bun is running?
0.8.1+16b4bf341acc0f4804f0b6bdf5298c180cd00366
What platform is your computer?
Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
What is the expected behavior?
When using, Node (v20) with the
ws
module from NPM, (so don't forget to add theimport WebSocket from "ws";
at the top), with the exact same code, we get the WebSocket connection ready and working:(message received from server on connection)
What do you see instead?
When running the following with Bun (
bun run index.ts
), we getIn fact, we received a 403 status code.
Additional information
Appears to be an issue with the headers casing.
When using
Origin: ...
in Bun, it sends in realityorigin: ...
and as you can see, this is incorrect because theo
is in lowercase.HTTP 1.1 specification says that the casing is not sensitive but some servers decided that it is (just see my example above with the Discord Remote Auth Gateway)
This issue happens on every single headers, they're all getting lowercased and that's a major issue.
The text was updated successfully, but these errors were encountered: