UNPKG

@zougui/furaffinity

Version:

45 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hHttpClient = void 0; class hHttpClient { constructor() { this.fetch = async (url, config) => { const headers = new Headers(); const reqOpts = { method: (config === null || config === void 0 ? void 0 : config.method) || 'GET', mode: 'no-cors', credentials: (config === null || config === void 0 ? void 0 : config.cookies) ? 'include' : undefined, headers, }; if (config === null || config === void 0 ? void 0 : config.cookies) { headers.set('Cookie', config.cookies); } if (config === null || config === void 0 ? void 0 : config.body) { if (config.contentType === 'application/x-www-form-urlencoded') { const fd = new FormData(); for (const k of Object.keys(config.body)) { const v = config.body[k]; if (Array.isArray(v)) { // repeat key v.forEach(val => fd.append(k, String(val))); } else { fd.append(k, String(v)); } } reqOpts.body = fd; } else { reqOpts.body = JSON.stringify(config.body); } } const res = await fetch(url, reqOpts); return { statusCode: res.status, body: await res.text(), }; }; } } exports.hHttpClient = hHttpClient; //# sourceMappingURL=HttpClient.js.map