Skip to content

Commit

Permalink
Merge pull request #203 from kbakk/client-negotiate-version
Browse files Browse the repository at this point in the history
feat: add option for client to set negotiateVersion
  • Loading branch information
philippseith authored Sep 26, 2024
2 parents f17a609 + b492a61 commit d47b125
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions httpconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type Doer interface {
}

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

// WithHTTPClient sets the http client used to connect to the signalR server.
Expand Down Expand Up @@ -56,6 +57,14 @@ func WithTransports(transports ...TransportType) func(*httpConnection) error {
}
}

// WithNegotiateVersion sets the negotiate version to use for the SignalR negotiation.
func WithNegotiateVersion(version int) func(*httpConnection) error {
return func(c *httpConnection) error {
c.negotiateVersion = &version
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 Down Expand Up @@ -84,6 +93,11 @@ func NewHTTPConnection(ctx context.Context, address string, options ...func(*htt

negotiateURL := *reqURL
negotiateURL.Path = path.Join(negotiateURL.Path, "negotiate")
if httpConn.negotiateVersion != nil {
q := negotiateURL.Query()
q.Set("negotiateVersion", fmt.Sprint(*httpConn.negotiateVersion))
negotiateURL.RawQuery = q.Encode()
}
req, err := http.NewRequestWithContext(ctx, "POST", negotiateURL.String(), nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit d47b125

Please sign in to comment.