MCPcopy Create free account
hub / github.com/langgenius/dify / compileState

Function compileState

cli/src/http/client.ts:49–79  ·  view source on GitHub ↗
(opts: ClientOptions)

Source from the content-addressed store, hash-verified

47}
48
49function compileState(opts: ClientOptions): ClientState {
50 const onRequest: Hook[] = []
51 const onResponse: Hook[] = []
52 const onRequestError: Hook[] = [classifyTransport]
53 const onResponseError: Hook[] = []
54
55 // Always pin a difyctl-shaped UA so server logs / WAF rules see the CLI's
56 // version + platform. Callers can override by passing `userAgent` explicitly.
57 onRequest.push(setUserAgent(opts.userAgent ?? defaultUserAgent()))
58 if (opts.bearer !== undefined && opts.bearer !== '')
59 onRequest.push(setBearer(opts.bearer))
60 if (opts.logger !== undefined) {
61 onRequest.push(logRequest(opts.logger))
62 onResponse.push(logResponse(opts.logger))
63 }
64
65 onRequest.push(...toArray(opts.hooks?.onRequest))
66 onResponse.push(...toArray(opts.hooks?.onResponse))
67 onRequestError.push(...toArray(opts.hooks?.onRequestError))
68 onResponseError.push(...toArray(opts.hooks?.onResponseError))
69
70 return {
71 baseURL: opts.baseURL,
72 defaultTimeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
73 defaultRetryAttempts: opts.retryAttempts ?? DEFAULT_RETRY_ATTEMPTS,
74 hooks: { onRequest, onResponse, onRequestError, onResponseError },
75 logger: opts.logger,
76 originalOptions: opts,
77 dispatcher: proxyDispatcher(),
78 }
79}
80
81async function runHooks(hooks: readonly Hook[], ctx: FetchContext): Promise<void> {
82 for (const hook of hooks)

Callers 1

createHttpClientFunction · 0.85

Calls 7

setUserAgentFunction · 0.85
setBearerFunction · 0.85
logRequestFunction · 0.85
logResponseFunction · 0.85
toArrayFunction · 0.85
proxyDispatcherFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected