Skip to content

Commit f6524dd

Browse files
committed
ae.net.http.websocket: Accept comma-separated Connection header tokens
Allow WebSocket accept() to handle HTTP Connection headers with comma-separated tokens, per HTTP/1.1 semantics, instead of requiring the header value to be exactly "Upgrade". The check now splits on commas, strips whitespace, and matches any token case-insensitively.
1 parent ceb661a commit f6524dd

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

net/http/websocket.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,11 @@ protected:
467467

468468
import ae.net.http.common : HttpRequest, HttpResponse, HttpStatusCode;
469469
import ae.net.http.server : HttpServerConnection;
470+
import std.algorithm.iteration : splitter;
471+
import std.algorithm.searching : any;
470472
import std.base64 : Base64;
471473
import std.digest.sha : sha1Of;
474+
import std.string : strip;
472475

473476
private enum wsGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
474477

@@ -484,7 +487,7 @@ WebSocketAdapter accept(
484487
request.method == "GET" &&
485488
request.protocolVersion >= "1.1" &&
486489
request.headers.get("Upgrade", null).icmp("websocket") == 0 &&
487-
request.headers.get("Connection", null).icmp("Upgrade") == 0 &&
490+
request.headers.get("Connection", null).splitter(",").any!(t => t.strip.icmp("Upgrade") == 0) &&
488491
"Sec-WebSocket-Key" in request.headers &&
489492
request.headers.get("Sec-WebSocket-Version", null) == "13",
490493
"Invalid WebSockets request"

0 commit comments

Comments
 (0)