mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
supposedly it is faster, and anyway it's better to use it since we're already using it for wasm/js. (previously named nhooyr/websocket).
35 lines
728 B
Go
35 lines
728 B
Go
//go:build !js
|
|
|
|
package nostr
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net/http"
|
|
"net/textproto"
|
|
|
|
ws "github.com/coder/websocket"
|
|
)
|
|
|
|
var defaultConnectionOptions = &ws.DialOptions{
|
|
CompressionMode: ws.CompressionContextTakeover,
|
|
HTTPHeader: http.Header{
|
|
textproto.CanonicalMIMEHeaderKey("User-Agent"): {"github.com/nbd-wtf/go-nostr"},
|
|
},
|
|
}
|
|
|
|
func getConnectionOptions(requestHeader http.Header, tlsConfig *tls.Config) *ws.DialOptions {
|
|
if requestHeader == nil && tlsConfig == nil {
|
|
return defaultConnectionOptions
|
|
}
|
|
|
|
return &ws.DialOptions{
|
|
HTTPHeader: requestHeader,
|
|
CompressionMode: ws.CompressionContextTakeover,
|
|
HTTPClient: &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: tlsConfig,
|
|
},
|
|
},
|
|
}
|
|
}
|