MCPcopy
hub / github.com/di-sukharev/opencommit / sendRequest

Method sendRequest

out/cli.cjs:76696–76791  ·  view source on GitHub ↗

* Makes a request over an underlying transport layer and returns the response. * @param request - The request to be made.

(request3)

Source from the content-addressed store, hash-verified

76694var NodeHttpClient = class {
76695 constructor() {
76696 this.cachedHttpsAgents = /* @__PURE__ */ new WeakMap();
76697 }
76698 /**
76699 * Makes a request over an underlying transport layer and returns the response.
76700 * @param request - The request to be made.
76701 */
76702 async sendRequest(request3) {
76703 var _a5, _b2, _c2;
76704 const abortController = new AbortController();
76705 let abortListener;
76706 if (request3.abortSignal) {
76707 if (request3.abortSignal.aborted) {
76708 throw new AbortError("The operation was aborted.");
76709 }
76710 abortListener = (event) => {
76711 if (event.type === "abort") {
76712 abortController.abort();
76713 }
76714 };
76715 request3.abortSignal.addEventListener("abort", abortListener);
76716 }
76717 if (request3.timeout > 0) {
76718 setTimeout(() => {
76719 abortController.abort();
76720 }, request3.timeout);
76721 }
76722 const acceptEncoding = request3.headers.get("Accept-Encoding");
76723 const shouldDecompress = (acceptEncoding === null || acceptEncoding === void 0 ? void 0 : acceptEncoding.includes("gzip")) || (acceptEncoding === null || acceptEncoding === void 0 ? void 0 : acceptEncoding.includes("deflate"));
76724 let body = typeof request3.body === "function" ? request3.body() : request3.body;
76725 if (body && !request3.headers.has("Content-Length")) {
76726 const bodyLength = getBodyLength2(body);
76727 if (bodyLength !== null) {
76728 request3.headers.set("Content-Length", bodyLength);
76729 }
76730 }
76731 let responseStream;
76732 try {
76733 if (body && request3.onUploadProgress) {
76734 const onUploadProgress = request3.onUploadProgress;
76735 const uploadReportStream = new ReportTransform(onUploadProgress);
76736 uploadReportStream.on("error", (e3) => {
76737 logger.error("Error in upload progress", e3);
76738 });
76739 if (isReadableStream2(body)) {
76740 body.pipe(uploadReportStream);
76741 } else {
76742 uploadReportStream.end(body);
76743 }
76744 body = uploadReportStream;
76745 }
76746 const res = await this.makeRequest(request3, abortController, body);
76747 const headers = getResponseHeaders(res);
76748 const status = (_a5 = res.statusCode) !== null && _a5 !== void 0 ? _a5 : 0;
76749 const response = {
76750 status,
76751 headers,
76752 request: request3
76753 };

Callers 2

sendRequestMethod · 0.45
sendRequestFunction · 0.45

Calls 15

setTimeoutFunction · 0.85
getBodyLength2Function · 0.85
isReadableStream2Function · 0.85
getResponseHeadersFunction · 0.85
getDecodedResponseStreamFunction · 0.85
streamToTextFunction · 0.85
isStreamCompleteFunction · 0.85
includesMethod · 0.80
pipeMethod · 0.80
endMethod · 0.80
makeRequestMethod · 0.80
resumeMethod · 0.80

Tested by

no test coverage detected