MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getTransportForUrl

Function getTransportForUrl

src/cli/transports/transportUtils.ts:16–45  ·  view source on GitHub ↗
(
  url: URL,
  headers: Record<string, string> = {},
  sessionId?: string,
  refreshHeaders?: () => Record<string, string>,
)

Source from the content-addressed store, hash-verified

14 * 3. WebSocketTransport (WS reads + WS writes) — default
15 */
16export function getTransportForUrl(
17 url: URL,
18 headers: Record<string, string> = {},
19 sessionId?: string,
20 refreshHeaders?: () => Record<string, string>,
21): Transport {
22 if (isEnvTruthy(process.env.CLAUDE_CODE_USE_CCR_V2)) {
23 // v2: SSE for reads, HTTP POST for writes
24 // --sdk-url is the session URL (.../sessions/{id});
25 // derive the SSE stream URL by appending /worker/events/stream
26 const sseUrl = new URL(url.href)
27 if (sseUrl.protocol === 'wss:') {
28 sseUrl.protocol = 'https:'
29 } else if (sseUrl.protocol === 'ws:') {
30 sseUrl.protocol = 'http:'
31 }
32 sseUrl.pathname =
33 sseUrl.pathname.replace(/\/$/, '') + '/worker/events/stream'
34 return new SSETransport(sseUrl, headers, sessionId, refreshHeaders)
35 }
36
37 if (url.protocol === 'ws:' || url.protocol === 'wss:') {
38 if (isEnvTruthy(process.env.CLAUDE_CODE_POST_FOR_SESSION_INGRESS_V2)) {
39 return new HybridTransport(url, headers, sessionId, refreshHeaders)
40 }
41 return new WebSocketTransport(url, headers, sessionId, refreshHeaders)
42 } else {
43 throw new Error(`Unsupported protocol: ${url.protocol}`)
44 }
45}
46
47

Callers 1

constructorMethod · 0.85

Calls 1

isEnvTruthyFunction · 0.85

Tested by

no test coverage detected