UNPKG

node-tls-client-kgb

Version:

Advanced library based on node-fetch and tls-client.

55 lines (54 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isByteRequest = void 0; const exactContentTypes = new Set([ "application/octet-stream", "application/pdf", "application/zip", "application/gzip", "application/x-rar-compressed", "application/x-msdownload", "application/x-sh", "application/x-binary", "base64", ]); const prefixContentTypes = new Set([ "image/", "audio/", "video/", "application/vnd.", ]); /** * Determines if a request should be treated as a byte request based on its headers. * * This function checks the "Content-Type" and "Content-Transfer-Encoding" headers * to determine if the request is for binary data (such as images, audio, video, * application binaries, etc.). If the headers indicate binary data, it returns true. * * @param {OutgoingHttpHeaders} headers - The headers of the request. * @returns {boolean} - Returns true if the request is for binary data, otherwise false. */ function isByteRequest(headers) { const contentType = headers["content-type"] || headers["Content-Type"]; const contentTransferEncoding = headers["content-transfer-encoding"] || headers["Content-Transfer-Encoding"]; if (contentTransferEncoding) { const encodingString = String(contentTransferEncoding); if (exactContentTypes.has(encodingString)) { return true; } } if (contentType) { const contentTypeString = String(contentType); if (exactContentTypes.has(contentTypeString)) { return true; } for (const prefix of prefixContentTypes) { if (contentTypeString.startsWith(prefix)) { return true; } } } return false; } exports.isByteRequest = isByteRequest;