MCPcopy Create free account
hub / github.com/coder/coder / buildRelayURL

Function buildRelayURL

enterprise/coderd/x/chatd/chatd.go:837–860  ·  view source on GitHub ↗

buildRelayURL builds the websocket URL for the chat stream endpoint on a peer replica. It maps http(s) schemes to ws(s).

(address string, chatID uuid.UUID)

Source from the content-addressed store, hash-verified

835// buildRelayURL builds the websocket URL for the chat stream
836// endpoint on a peer replica. It maps http(s) schemes to ws(s).
837func buildRelayURL(address string, chatID uuid.UUID) (string, error) {
838 u, err := url.Parse(address)
839 if err != nil {
840 return "", xerrors.Errorf("parse relay address %q: %w", address, err)
841 }
842 switch u.Scheme {
843 case "http":
844 u.Scheme = "ws"
845 case "https":
846 u.Scheme = "wss"
847 case "ws", "wss":
848 // already a websocket URL, leave as-is.
849 default:
850 return "", xerrors.Errorf("unsupported relay address scheme %q", u.Scheme)
851 }
852 u.Path = fmt.Sprintf("/api/experimental/chats/%s/stream", chatID)
853 q := u.Query()
854 // Relays only need live message_part events, not the full
855 // history; pass the relay sentinel so the peer skips its
856 // durable DB snapshot and delivers in-flight parts only.
857 q.Set("after_id", strconv.FormatInt(osschatd.RelaySentinelAfterID, 10))
858 u.RawQuery = q.Encode()
859 return u.String(), nil
860}
861
862// extractSessionToken returns the session token carried by the
863// given request headers. It mirrors the priority order used by

Callers 1

dialRelayFunction · 0.85

Calls 5

EncodeMethod · 0.80
ParseMethod · 0.65
SetMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected