MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / run

Method run

packages/components/nodes/agentflow/HTTP/HTTP.ts:204–377  ·  view source on GitHub ↗
(nodeData: INodeData, _: string, options: ICommonObject)

Source from the content-addressed store, hash-verified

202 }
203
204 async run(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
205 const method = nodeData.inputs?.method as 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
206 const url = nodeData.inputs?.url as string
207 const headers = nodeData.inputs?.headers as ICommonObject
208 const queryParams = nodeData.inputs?.queryParams as ICommonObject
209 const bodyType = nodeData.inputs?.bodyType as 'json' | 'raw' | 'formData' | 'xWwwFormUrlencoded'
210 const body = nodeData.inputs?.body as ICommonObject | string | ICommonObject[]
211 const responseType = nodeData.inputs?.responseType as 'json' | 'text' | 'arraybuffer' | 'base64'
212
213 const state = options.agentflowRuntime?.state as ICommonObject
214
215 try {
216 // Prepare headers
217 const requestHeaders: Record<string, string> = {}
218
219 // Add headers from inputs
220 if (headers && Array.isArray(headers)) {
221 for (const header of headers) {
222 if (header.key && header.value) {
223 requestHeaders[header.key] = header.value
224 }
225 }
226 }
227
228 // Add credentials if provided
229 const credentialData = await getCredentialData(nodeData.credential ?? '', options)
230 if (credentialData && Object.keys(credentialData).length !== 0) {
231 const basicAuthUsername = getCredentialParam('basicAuthUsername', credentialData, nodeData)
232 const basicAuthPassword = getCredentialParam('basicAuthPassword', credentialData, nodeData)
233 const bearerToken = getCredentialParam('token', credentialData, nodeData)
234 const apiKeyName = getCredentialParam('key', credentialData, nodeData)
235 const apiKeyValue = getCredentialParam('value', credentialData, nodeData)
236
237 // Determine which type of auth to use based on available credentials
238 if (basicAuthUsername || basicAuthPassword) {
239 // Basic Auth
240 const auth = Buffer.from(`${basicAuthUsername}:${basicAuthPassword}`).toString('base64')
241 requestHeaders['Authorization'] = `Basic ${auth}`
242 } else if (bearerToken) {
243 // Bearer Token
244 requestHeaders['Authorization'] = `Bearer ${bearerToken}`
245 } else if (apiKeyName && apiKeyValue) {
246 // API Key in header
247 requestHeaders[apiKeyName] = apiKeyValue
248 }
249 }
250
251 // Prepare query parameters
252 let queryString = ''
253 if (queryParams && Array.isArray(queryParams)) {
254 const params = new URLSearchParams()
255 for (const param of queryParams) {
256 if (param.key && param.value) {
257 params.append(param.key, param.value)
258 }
259 }
260 queryString = params.toString()
261 }

Callers

nothing calls this directly

Calls 5

getCredentialDataFunction · 0.90
getCredentialParamFunction · 0.90
parseJsonBodyFunction · 0.90
secureAxiosRequestFunction · 0.90
stringifyMethod · 0.80

Tested by

no test coverage detected