Skip to content

Commit

Permalink
Merge pull request #175 from philippseith/feature/client_fallback_sse
Browse files Browse the repository at this point in the history
Feature/client fallback sse
  • Loading branch information
philippseith authored Sep 12, 2023
2 parents 94de338 + 882ea7e commit 6bda772
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 96 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.51
version: v1.54

test:
name: Test and Coverage
Expand All @@ -27,12 +27,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16
go-version: 1.18

- name: Check out code
uses: actions/checkout@v1

- name: Run Unit tests.
- name: Run Unit tests
run: make test-coverage

- name: Upload Coverage report to CodeCov
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16
go-version: 1.18

- name: Check out code
uses: actions/checkout@v1
Expand Down
6 changes: 3 additions & 3 deletions .run/go test signalr_test.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<framework value="gotest" />
<method v="2" />
</configuration>
<configuration default="false" name="go test signalr_test" type="GoTestRunConfiguration" factoryName="Go Test" nameIsGenerated="true">
<configuration default="false" name="go test signalr_test" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="signalr" />
<working_directory value="$PROJECT_DIR$/signalr_test" />
<go_parameters value="-race -count=1 -v" />
<kind value="DIRECTORY" />
<package value="github.com/philippseith/signalr" />
<kind value="PACKAGE" />
<package value="github.com/philippseith/signalr/signalr_test" />
<directory value="$PROJECT_DIR$/signalr_test" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test-coverage: ## Run tests with coverage
@cat cover.out >> coverage.txt

build: dep ## Build the binary file
@go build -i -o build/main $(PKG)
@go build -o build/main $(PKG)

clean: ## Remove previous build
@rm -f $(PROJECT_NAME)/build
Expand Down
56 changes: 55 additions & 1 deletion clientoptions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package signalr

import (
"context"
"errors"
"fmt"

"github.com/cenkalti/backoff/v4"
)

Expand Down Expand Up @@ -36,6 +38,58 @@ func WithConnector(connectionFactory func() (Connection, error)) func(Party) err
}
}

// HttpConnectionFactory is a connectionFactory for WithConnector which first tries to create a connection
// with WebSockets (if it is allowed by the HttpConnection options) and if this fails, falls back to a SSE based connection.
func HttpConnectionFactory(ctx context.Context, address string, options ...func(*httpConnection) error) (Connection, error) {
conn := &httpConnection{}
for i, option := range options {
if err := option(conn); err != nil {
return nil, err
}
if conn.transports != nil {
// Remove the WithTransports option
options = append(options[:i], options[i+1:]...)
break
}
}
// If no WithTransports was given, NewHTTPConnection fallbacks to both
if conn.transports == nil {
conn.transports = []TransportType{TransportWebSockets, TransportServerSentEvents}
}

for _, transport := range conn.transports {
// If Websockets are allowed, we try to connect with these
if transport == TransportWebSockets {
wsOptions := append(options, WithTransports(TransportWebSockets))
conn, err := NewHTTPConnection(ctx, address, wsOptions...)
// If this is ok, return the conn
if err == nil {
return conn, err
}
break
}
}
for _, transport := range conn.transports {
// If SSE is allowed, with fallback to try these
if transport == TransportServerSentEvents {
sseOptions := append(options, WithTransports(TransportServerSentEvents))
return NewHTTPConnection(ctx, address, sseOptions...)
}
}
// None of the transports worked
return nil, fmt.Errorf("can not connect with supported transports: %v", conn.transports)
}

// WithHttpConnection first tries to create a connection
// with WebSockets (if it is allowed by the HttpConnection options) and if this fails, falls back to a SSE based connection.
// This strategy is also used for auto reconnect if this option is used.
// WithHttpConnection is a shortcut for WithConnector(HttpConnectionFactory(...))
func WithHttpConnection(ctx context.Context, address string, options ...func(*httpConnection) error) func(Party) error {
return WithConnector(func() (Connection, error) {
return HttpConnectionFactory(ctx, address, options...)
})
}

// WithReceiver sets the object which will receive server side calls to client methods (e.g. callbacks)
func WithReceiver(receiver interface{}) func(Party) error {
return func(party Party) error {
Expand Down Expand Up @@ -64,7 +118,7 @@ func WithBackoff(backoffFactory func() backoff.BackOff) func(party Party) error
}

// TransferFormat sets the transfer format used on the transport. Allowed values are "Text" and "Binary"
func TransferFormat(format string) func(Party) error {
func TransferFormat(format TransferFormatType) func(Party) error {
return func(p Party) error {
if c, ok := p.(*client); ok {
switch format {
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ which kind of connection (Websockets, Server-Sent Events) will be used.
// Client with JSON encoding
client, err := NewClient(ctx,
WithConnection(conn),
TransferFormat("Text"),
TransferFormat(TransferFormatText),
WithReceiver(receiver))
client.Start()
Expand Down
12 changes: 11 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/philippseith/signalr

go 1.16
go 1.18

require (
github.com/cenkalti/backoff/v4 v4.2.1
Expand All @@ -16,7 +16,17 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/nxadm/tail v1.4.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.10.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
27 changes: 1 addition & 26 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQ
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/teivah/onecontext v1.3.0 h1:tbikMhAlo6VhAuEGCvhc8HlTnpX4xTNPTOseWuhO1J0=
Expand All @@ -97,61 +93,40 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
48 changes: 38 additions & 10 deletions httpconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type Doer interface {
}

type httpConnection struct {
client Doer
headers func() http.Header
client Doer
headers func() http.Header
transports []TransportType
}

// WithHTTPClient sets the http client used to connect to the signalR server.
Expand All @@ -39,6 +40,21 @@ func WithHTTPHeaders(headers func() http.Header) func(*httpConnection) error {
}
}

func WithTransports(transports ...TransportType) func(*httpConnection) error {
return func(c *httpConnection) error {
for _, transport := range transports {
switch transport {
case TransportWebSockets, TransportServerSentEvents:
// Supported
default:
return fmt.Errorf("unsupported transport %s", transport)
}
}
c.transports = transports
return nil
}
}

// NewHTTPConnection creates a signalR HTTP Connection for usage with a Client.
// ctx can be used to cancel the SignalR negotiation during the creation of the Connection
// but not the Connection itself.
Expand All @@ -56,6 +72,9 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt
if httpConn.client == nil {
httpConn.client = http.DefaultClient
}
if len(httpConn.transports) == 0 {
httpConn.transports = []TransportType{TransportWebSockets, TransportServerSentEvents}
}

reqURL, err := url.Parse(address)
if err != nil {
Expand Down Expand Up @@ -88,22 +107,22 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt
return nil, err
}

nr := negotiateResponse{}
if err := json.Unmarshal(body, &nr); err != nil {
negotiateResponse := negotiateResponse{}
if err := json.Unmarshal(body, &negotiateResponse); err != nil {
return nil, err
}

q := reqURL.Query()
q.Set("id", nr.ConnectionID)
q.Set("id", negotiateResponse.ConnectionID)
reqURL.RawQuery = q.Encode()

// Select the best connection
var conn Connection
switch {
case nr.getTransferFormats("WebTransports") != nil:
case negotiateResponse.hasTransport("WebTransports"):
// TODO

case nr.getTransferFormats("WebSockets") != nil:
case httpConn.hasTransport(TransportWebSockets) && negotiateResponse.hasTransport(TransportWebSockets):
wsURL := reqURL

// switch to wss for secure connection
Expand Down Expand Up @@ -131,9 +150,9 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt
}

// TODO think about if the API should give the possibility to cancel this connection
conn = newWebSocketConnection(context.Background(), nr.ConnectionID, ws)
conn = newWebSocketConnection(context.Background(), negotiateResponse.ConnectionID, ws)

case nr.getTransferFormats("ServerSentEvents") != nil:
case httpConn.hasTransport(TransportServerSentEvents) && negotiateResponse.hasTransport(TransportServerSentEvents):
req, err := http.NewRequest("GET", reqURL.String(), nil)
if err != nil {
return nil, err
Expand All @@ -149,7 +168,7 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt
return nil, err
}

conn, err = newClientSSEConnection(address, nr.ConnectionID, resp.Body)
conn, err = newClientSSEConnection(address, negotiateResponse.ConnectionID, resp.Body)
if err != nil {
return nil, err
}
Expand All @@ -165,3 +184,12 @@ func closeResponseBody(body io.ReadCloser) {
_, _ = io.Copy(io.Discard, body)
_ = body.Close()
}

func (h *httpConnection) hasTransport(transport TransportType) bool {
for _, t := range h.transports {
if transport == t {
return true
}
}
return false
}
12 changes: 6 additions & 6 deletions httpmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ func (h *httpMux) negotiate(w http.ResponseWriter, req *http.Request) {
var availableTransports []availableTransport
for _, transport := range h.server.availableTransports() {
switch transport {
case "ServerSentEvents":
case TransportServerSentEvents:
availableTransports = append(availableTransports,
availableTransport{
Transport: "ServerSentEvents",
TransferFormats: []string{"Text"},
Transport: string(TransportServerSentEvents),
TransferFormats: []string{string(TransferFormatText)},
})
case "WebSockets":
case TransportWebSockets:
availableTransports = append(availableTransports,
availableTransport{
Transport: "WebSockets",
TransferFormats: []string{"Text", "Binary"},
Transport: string(TransportWebSockets),
TransferFormats: []string{string(TransferFormatText), string(TransferFormatBinary)},
})
}
}
Expand Down
Loading

0 comments on commit 6bda772

Please sign in to comment.