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

Function buildRequest

cli/src/http/client.ts:117–140  ·  view source on GitHub ↗
(state: ClientState, path: string, opts: RequestOptions, throwOnErrorDefault: boolean)

Source from the content-addressed store, hash-verified

115// WITHOUT a signal — execute() supplies a fresh per-attempt signal via fetch's
116// init.signal (which overrides any signal carried on the Request).
117function buildRequest(state: ClientState, path: string, opts: RequestOptions, throwOnErrorDefault: boolean): BuiltRequest {
118 const method: HttpMethod = opts.method ?? 'GET'
119 const effectiveTimeoutMs = opts.timeoutMs !== undefined
120 ? (opts.timeoutMs > 0 ? opts.timeoutMs : undefined)
121 : state.defaultTimeoutMs
122 const effectiveRetryAttempts = opts.retryAttempts ?? state.defaultRetryAttempts
123 const throwOnError = opts.throwOnError ?? throwOnErrorDefault
124
125 const { body, contentType } = buildBody({ json: opts.json, body: opts.body, method })
126 const headers = mergeHeaders(opts.headers, contentType)
127 const url = appendSearchParams(joinURL(state.baseURL, path), opts.searchParams)
128
129 const request = new Request(url, { method, headers, body })
130 const resolved: ResolvedOptions = {
131 method,
132 headers,
133 body,
134 timeoutMs: effectiveTimeoutMs,
135 retryAttempts: effectiveRetryAttempts,
136 throwOnError,
137 retryOnRateLimit: opts.retryOnRateLimit ?? false,
138 }
139 return { request, resolved, effectiveTimeoutMs, userSignal: opts.signal }
140}
141
142// The shared transport engine: hooks -> fetch -> retry -> error-map. Accepts an
143// already-built Request, so both the path entrypoints (via buildRequest) and the

Callers 3

typedCallFunction · 0.85
rawFetchFunction · 0.85
streamFetchFunction · 0.85

Calls 4

buildBodyFunction · 0.85
mergeHeadersFunction · 0.85
joinURLFunction · 0.85
appendSearchParamsFunction · 0.70

Tested by

no test coverage detected