MCPcopy Create free account
hub / github.com/EsperoTech/yaade / sendRequest

Function sendRequest

client/src/components/requestPanel/RequestSender.tsx:231–345  ·  view source on GitHub ↗
(
    request: RestRequest,
    reqCollections: Collection[],
    envName?: string,
    n?: number,
  )

Source from the content-addressed store, hash-verified

229 };
230
231 async function sendRequest(
232 request: RestRequest,
233 reqCollections: Collection[],
234 envName?: string,
235 n?: number,
236 ): Promise<RestResponse> {
237 if (n && n >= 5) {
238 throw Error('Exec loop detected in request script');
239 }
240
241 const collection = findCollection(reqCollections, request.collectionId);
242 const headers = getMergedHeaders(request, reqCollections);
243 let auth = collection?.data?.auth;
244 if (request.data.auth && request.data.auth.enabled) {
245 auth = request.data.auth;
246 }
247
248 const injectedReq: RestRequest = {
249 ...request,
250 data: {
251 ...request.data,
252 auth,
253 headers,
254 },
255 };
256
257 let proxy = 'ext';
258 const env = getEnv(injectedReq.collectionId, envName);
259 if (env) {
260 proxy = env.proxy;
261 }
262
263 if (collection?.data?.requestScript) {
264 if (proxy === 'ext' && getMinorVersion(extVersion.current) < 3) {
265 throw Error(`Request scripts are not supported in this version of the extension.
266 Please update to the latest version or remove the request script.`);
267 }
268 await doRequestScript(
269 injectedReq,
270 reqCollections,
271 collection?.data?.requestScript,
272 true,
273 envName,
274 n,
275 );
276 }
277
278 if (injectedReq.data.requestScript) {
279 if (proxy === 'ext' && getMinorVersion(extVersion.current) < 3) {
280 throw Error(`Request scripts are not supported in this version of the extension.
281 Please update to the latest version or remove the request script.`);
282 }
283 await doRequestScript(
284 injectedReq,
285 reqCollections,
286 injectedReq.data.requestScript,
287 false,
288 envName,

Callers 3

execFunction · 0.70
RequestSenderFunction · 0.70
handleSendButtonClickFunction · 0.70

Calls 8

findCollectionFunction · 0.90
getMergedHeadersFunction · 0.90
getMinorVersionFunction · 0.90
doRequestScriptFunction · 0.85
sendRequestToServerFunction · 0.85
sendRequestToExtensionFunction · 0.85
doResponseScriptFunction · 0.85
getEnvFunction · 0.70

Tested by

no test coverage detected