Skip to content

Commit

Permalink
Correct context
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Oct 22, 2022
1 parent 4926b04 commit 90bf9b8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ws/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ func (o *ClientOptions) dial(ctx context.Context) (context.Context, *websocket.C

header := metadata.Join(
metadata.MD(o.DialOptions.HTTPHeader),
mdFromContext(o.DialContext),
mdFromContext(ctx),
fromOutgoingContext(o.DialContext),
fromOutgoingContext(ctx),
)
if o.DialContext != nil {
ctx = o.DialContext

dialContext := o.DialContext
if dialContext == nil {
dialContext = ctx
}

// Dial service
ws, res, err := websocket.Dial(ctx, o.URL, &websocket.DialOptions{
ws, res, err := websocket.Dial(dialContext, o.URL, &websocket.DialOptions{
HTTPClient: o.DialOptions.HTTPClient,
HTTPHeader: http.Header(header),
Subprotocols: o.DialOptions.Subprotocols,
Expand Down Expand Up @@ -71,7 +73,7 @@ func (e *dialErr) Error() string {
}
func (e *dialErr) Unwrap() error { return e.error }

func mdFromContext(ctx context.Context) metadata.MD {
func fromOutgoingContext(ctx context.Context) metadata.MD {
if ctx == nil {
return nil
}
Expand Down

0 comments on commit 90bf9b8

Please sign in to comment.