(
request: RestRequest,
reqCollections: Collection[],
envName?: string,
n?: number,
)
| 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, |
no test coverage detected