"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "invokeRequest", {
    enumerable: true,
    get: function() {
        return invokeRequest;
    }
});
const _utils = require("./utils");
const invokeRequest = async (targetUrl, requestInit, readableBody)=>{
    // force to 127.0.0.1 as IPC always runs on this hostname
    // to avoid localhost issues
    const parsedTargetUrl = new URL(targetUrl);
    parsedTargetUrl.hostname = "127.0.0.1";
    const invokeHeaders = (0, _utils.filterReqHeaders)({
        "cache-control": "",
        ...requestInit.headers
    });
    return await fetch(parsedTargetUrl.toString(), {
        headers: invokeHeaders,
        method: requestInit.method,
        redirect: "manual",
        signal: requestInit.signal,
        ...requestInit.method !== "GET" && requestInit.method !== "HEAD" && readableBody ? {
            body: readableBody,
            duplex: "half"
        } : {},
        next: {
            // @ts-ignore
            internal: true
        }
    });
};

//# sourceMappingURL=invoke-request.js.map