add RequestHeader option for websocket conn

This commit is contained in:
Jasper Rädisch
2023-02-21 13:12:23 +01:00
committed by fiatjaf_
parent 17a7c3a678
commit 74c646fe21
2 changed files with 25 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
"time"
@@ -36,7 +37,8 @@ func (s Status) String() string {
}
type Relay struct {
URL string
URL string
RequestHeader http.Header // e.g. for origin header
Connection *Connection
subscriptions s.MapOf[string, *Subscription]
@@ -77,7 +79,7 @@ func (r *Relay) Connect(ctx context.Context) error {
defer cancel()
}
socket, _, err := websocket.DefaultDialer.DialContext(ctx, r.URL, nil)
socket, _, err := websocket.DefaultDialer.DialContext(ctx, r.URL, r.RequestHeader)
if err != nil {
return fmt.Errorf("error opening websocket to '%s': %w", r.URL, err)
}