MCPcopy Create free account
hub / github.com/di-sukharev/opencommit / buildRequest

Method buildRequest

out/cli.cjs:69659–69688  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

69657 if (typeof TextEncoder !== "undefined") {
69658 const encoder = new TextEncoder();
69659 const encoded = encoder.encode(body);
69660 return encoded.length.toString();
69661 }
69662 }
69663 return null;
69664 }
69665 buildRequest(options) {
69666 const { method, path: path5, query, headers = {} } = options;
69667 const body = isMultipartBody(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null;
69668 const contentLength = this.calculateContentLength(body);
69669 const url2 = this.buildURL(path5, query);
69670 if ("timeout" in options)
69671 validatePositiveInteger("timeout", options.timeout);
69672 const timeout = options.timeout ?? this.timeout;
69673 const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url2);
69674 const minAgentTimeout = timeout + 1e3;
69675 if (typeof httpAgent?.options?.timeout === "number" && minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
69676 httpAgent.options.timeout = minAgentTimeout;
69677 }
69678 if (this.idempotencyHeader && method !== "get") {
69679 if (!options.idempotencyKey)
69680 options.idempotencyKey = this.defaultIdempotencyKey();
69681 headers[this.idempotencyHeader] = options.idempotencyKey;
69682 }
69683 const reqHeaders = this.buildHeaders({ options, headers, contentLength });
69684 const req = {
69685 method,
69686 ...body && { body },
69687 headers: reqHeaders,
69688 ...httpAgent && { agent: httpAgent },
69689 // @ts-ignore node-fetch uses a custom AbortSignal type that is
69690 // not compatible with standard web types
69691 signal: options.signal ?? null

Callers 1

makeRequestMethod · 0.80

Calls 8

isMultipartBodyFunction · 0.85
validatePositiveIntegerFunction · 0.85
isMultipartBody2Function · 0.85
validatePositiveInteger2Function · 0.85
buildURLMethod · 0.80
defaultIdempotencyKeyMethod · 0.80
buildHeadersMethod · 0.80

Tested by

no test coverage detected