@galihrivanto/node-libcurli
Version:
Node.js bindings for curl-impersonate library
64 lines (63 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultResponseBodyParsers = exports.methods = void 0;
// This is basically http.METHODS
exports.methods = [
'acl',
'bind',
'checkout',
'connect',
'copy',
'delete',
'get',
'head',
'link',
'lock',
'm-search',
'merge',
'mkactivity',
'mkcalendar',
'mkcol',
'move',
'notify',
'options',
'patch',
'post',
'propfind',
'proppatch',
'purge',
'put',
'rebind',
'report',
'search',
'source',
'subscribe',
'trace',
'unbind',
'unlink',
'unlock',
'unsubscribe',
];
exports.defaultResponseBodyParsers = {
'application/json': (data, _headers) => {
try {
const string = data.toString('utf8');
return JSON.parse(string);
}
catch (error) {
throw new Error(`curly failed to parse "application/json" content as JSON. This is generally caused by receiving malformed JSON data from the server.
You can disable this automatic behavior by setting the option curlyResponseBodyParser to false, then a Buffer will be returned as the data.
You can also overwrite the "application/json" parser with your own by changing one of the following:
- curly.defaultResponseBodyParsers['application/json']
or
- options.curlyResponseBodyParsers = { 'application/json': parser }
If you want just a single function to handle all content-types, you can use the option "curlyResponseBodyParser".
`);
}
},
// We are in [INSERT CURRENT YEAR], let's assume everyone is using utf8 encoding for text/* content-type.
'text/*': (data, _headers) => data.toString('utf8'),
// otherwise let's just return the raw buffer
'*': (data, _headers) => data,
};
//# sourceMappingURL=curly.js.map