Skip to content

Commit

Permalink
Remove custom headers and unnecessary adjustment of content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed Feb 18, 2024
1 parent f1f1564 commit 08375d2
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@ const intToIp = (int) => {
return octets.join('.');
};

const customHeaders = ({ headers = {}, body }) => {
const mimeType = 'application/json';
const custom = { 'Content-Type': mimeType, ...headers };
if (body) custom['Content-Length'] = Buffer.byteLength(body);
return custom;
};

const httpApiCall = async (url, { method = 'POST', headers = {}, body }) => {
const custom = customHeaders({ headers, body });
const options = { method, headers: custom, body };
return await fetch(url, options).then((res) => {
const mimeType = 'application/json';
headers['Content-Type'] = mimeType;
return await fetch(url, { method, headers, body }).then((res) => {
const code = res.status;
if (code === 200) return res.json();
const dest = `for ${method} ${url}`;
Expand All @@ -56,5 +49,4 @@ module.exports = {
ipToInt,
intToIp,
httpApiCall,
customHeaders,
};

0 comments on commit 08375d2

Please sign in to comment.