RejectedSoftware Forums

Sign up

Add more headers to WebSocket

Hi,

Does anyone have an example on how to add more req.headers["whateverX"] to a WebSocket?

This is the vibe.d req.headers, and I want to append some more from within my subscribeWebSocket method.
auto res = requestHTTP(url, (scope req){

req.method = HTTPMethod.GET;
req.headers["Upgrade"] = "websocket";
req.headers["Connection"] = "Upgrade";
req.headers["Sec-WebSocket-Version"] = "13";
req.headers["Sec-WebSocket-Key"] = challengeKey;

});

WebSocket subscribeWebSocket()
{

auto ws_url = URL("wss://example.com/api/ws");
auto ws = connectWebSocket(ws_url);
return ws;

}

Thanks in advance.

Re: Add more headers to WebSocket

Am 26.09.2019 um 18:42 schrieb MrX:

Hi,

Does anyone have an example on how to add more req.headers["whateverX"] to a WebSocket?

This is the vibe.d req.headers, and I want to append some more from within my subscribeWebSocket method.
auto res = requestHTTP(url, (scope req){

req.method = HTTPMethod.GET;
req.headers["Upgrade"] = "websocket";
req.headers["Connection"] = "Upgrade";
req.headers["Sec-WebSocket-Version"] = "13";
req.headers["Sec-WebSocket-Key"] = challengeKey;

});

WebSocket subscribeWebSocket()
{

 auto ws_url = URL("wss://example.com/api/ws");
 auto ws = connectWebSocket(ws_url);
 return ws;

}

Thanks in advance.

I've opened a pull request to add this functionality now. With that
merged, the following will work:

auto ws = connectWebSocketEx(ws_url, (scope req) {
	req.headers["MyHeader"] = "foo";
});