From bec82c7d31da2db576af1d8c2a1c88c8b3976c8a Mon Sep 17 00:00:00 2001 From: dillondrobena Date: Tue, 12 Dec 2023 22:35:34 +0000 Subject: [PATCH] Use negotiateVersion from query parameter if present --- httpmux.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/httpmux.go b/httpmux.go index 0291c78..0cfe96e 100644 --- a/httpmux.go +++ b/httpmux.go @@ -194,10 +194,25 @@ func (h *httpMux) negotiate(w http.ResponseWriter, req *http.Request) { } else { connectionID := newConnectionID() connectionMapKey := connectionID - negotiateVersion, err := strconv.Atoi(req.Header.Get("negotiateVersion")) + + // Check the header for negotiateVersion + headerNegotiateVersion, err := strconv.Atoi(req.Header.Get("negotiateVersion")) + if err != nil { + headerNegotiateVersion = 0 + } + + // Check the query parameter for negotiateVersion + queryNegotiateVersion, err := strconv.Atoi(req.URL.Query().Get("negotiateVersion")) if err != nil { - negotiateVersion = 0 + queryNegotiateVersion = 0 } + + // Use the negotiateVersion from query if present, otherwise use the one from the header parameter + negotiateVersion := queryNegotiateVersion + if headerNegotiateVersion != 0 { + negotiateVersion = headerNegotiateVersion + } + connectionToken := "" if negotiateVersion == 1 { connectionToken = newConnectionID()