Skip to content

Commit

Permalink
fix: no connection with SSE version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
philippseith committed Apr 6, 2024
1 parent be8b443 commit db3d68b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions httpmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ func (h *httpMux) handleGet(writer http.ResponseWriter, request *http.Request) {
}

func (h *httpMux) handleServerSentEvent(writer http.ResponseWriter, request *http.Request) {
connectionID := request.URL.Query().Get("id")
if connectionID == "" {
connectionIDorToken := request.URL.Query().Get("id")
if connectionIDorToken == "" {
writer.WriteHeader(http.StatusBadRequest)
return
}
h.mx.RLock()
c, ok := h.connectionMap[connectionID]
c, ok := h.connectionMap[connectionIDorToken]
h.mx.RUnlock()
if ok {
if _, ok := c.(*negotiateConnection); ok {
ctx, _ := onecontext.Merge(h.server.context(), request.Context())
sseConn, jobChan, jobResultChan, err := newServerSSEConnection(ctx, c.ConnectionID())
sseConn, jobChan, jobResultChan, err := newServerSSEConnection(ctx, connectionIDorToken) // version 1 uses the token to initiate the connection, not the ID
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
return
Expand Down
11 changes: 8 additions & 3 deletions signalr_test/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -44,8 +45,12 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestServerSmoke(t *testing.T) {
testServer(t, "^smoke", signalr.HTTPTransports("WebSockets"))
func TestServerSmokeWebSockets(t *testing.T) {
testServer(t, "^smoke", signalr.HTTPTransports(signalr.TransportWebSockets))
}

func TestServerSmokeSSE(t *testing.T) {
testServer(t, "^smoke", signalr.HTTPTransports(signalr.TransportServerSentEvents))
}

func TestServerJsonWebSockets(t *testing.T) {
Expand Down Expand Up @@ -94,7 +99,7 @@ func runJest(t *testing.T, testNamePattern string, quitServer chan struct{}) {
t.Error(err, fmt.Sprintf("\n%s\n%s", outSlurp, errSlurp))
} else {
// Strange: Jest reports test results to stderr
t.Log(fmt.Sprintf("\n%s", errSlurp))
log.Printf("\n%s", errSlurp)
}
}

Expand Down

0 comments on commit db3d68b

Please sign in to comment.