From 14ec64a888286f8485b79f27d8166d704a91746f Mon Sep 17 00:00:00 2001 From: James Gray Date: Tue, 30 Jan 2024 15:32:46 +0200 Subject: [PATCH 1/2] Fixed so that cookies from Config are sent on websocket connection. --- http2.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/http2.d b/http2.d index 9d9e5a0..c3fe8fc 100644 --- a/http2.d +++ b/http2.d @@ -4618,6 +4618,7 @@ class WebSocket { socket = new Socket(family(uri.unixSocketPath), SocketType.STREAM); socket.setOption(SocketOptionLevel.TCP, SocketOption.TCP_NODELAY, 1); + cookies = config.cookies; } /++ @@ -4705,6 +4706,23 @@ class WebSocket { // FIXME: randomize this append("Sec-WebSocket-Key: x3JEHMbDL1EzLkh9GBhXDw==\r\n"); + append("cookie: "); + bool first=true; + foreach(k,v;cookies) { + if(first) first = false; + else append(" "); + append(k); + append("="); + append(v); + } + append("\r\n"); + /* + //This is equivalent but has dependencies + import std.format; + import std.algorithm : map; + append(format("cookie: %-(%s %)\r\n",cookies.byKeyValue.map!(t=>format("%s=%s",t.key,t.value)))); + */ + if(config.protocol.length) append("Sec-WebSocket-Protocol: ", config.protocol, "\r\n"); if(config.origin.length) From 1774aeb67ae387615cbfaaf627eaa205768cdcbd Mon Sep 17 00:00:00 2001 From: James Gray Date: Tue, 30 Jan 2024 16:09:50 +0200 Subject: [PATCH 2/2] Further changes to allow cookies to be sent from config when using websocket. 1. Only add 'Cookie' header if there are cookies. 2. Capatalize header. 3. Corrected separater to `; `. --- http2.d | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/http2.d b/http2.d index c3fe8fc..3003ba1 100644 --- a/http2.d +++ b/http2.d @@ -4705,17 +4705,18 @@ class WebSocket { // FIXME: randomize this append("Sec-WebSocket-Key: x3JEHMbDL1EzLkh9GBhXDw==\r\n"); - - append("cookie: "); - bool first=true; - foreach(k,v;cookies) { - if(first) first = false; - else append(" "); - append(k); - append("="); - append(v); + if(cookies.length > 0) { + append("Cookie: "); + bool first=true; + foreach(k,v;cookies) { + if(first) first = false; + else append("; "); + append(k); + append("="); + append(v); + } + append("\r\n"); } - append("\r\n"); /* //This is equivalent but has dependencies import std.format;