exports.id = 'httprequest'; exports.title = 'HTTP Request'; exports.group = 'HTTP'; exports.color = '#5D9CEC'; exports.input = true; exports.version = '2.0.1'; exports.output = 1; exports.author = 'Peter Širka'; exports.icon = 'cloud-upload'; exports.html = `
@(URL address)
@(HTTP method)
@(Serialization)
@(Download the content in chunks)
@(Keep persistent cookies)
@(Disable DNS cache)
@(Keep alive connection)

@(Custom headers)
@(Cookies)
@(User)
@(Password)
`; exports.readme = `# Request This component creates a request with received data. __Response:__ \`\`\`javascript { data: String, headers: Object, status: Number, host: String } \`\`\` __Dynamic arguments__: Are performed via FlowData repository and can be used for URL address or for custom headers/cookies/auth. Use \`repository\` component for creating of dynamic arguments. Dynamic values are replaced in the form \`{key}\`: - url address e.g. \`https://.../{key}/\` - headers values e.g. \`{token}\` - cookies values e.g. \`{token}\``; exports.install = function(instance) { var can = false; var flags = null; var cookies2 = null; instance.on('data', function(response) { can && instance.custom.send(response); }); instance.custom.send = function(response) { var options = instance.options; var headers = null; var cookies = null; options.headers && Object.keys(options.headers).forEach(function(key) { !headers && (headers = {}); headers[key] = response.arg(options.headers[key]); }); if (options.username && options.userpassword) { !headers && (headers = {}); headers['Authorization'] = 'Basic ' + U.createBuffer(response.arg(options.username + ':' + options.userpassword)).toString('base64'); } options.cookies && Object.keys(options.cookies).forEach(function(key) { !cookies && (cookies = {}); cookies[key] = response.arg(options.cookies[key]); }); if (options.chunks) { U.download(response.arg(options.url), flags, options.stringify === 'none' ? null : response.data, function(err, response) { response.on('data', (chunks) => instance.send2(chunks)); }, cookies || cookies2, headers); } else { U.request(response.arg(options.url), flags, options.stringify === 'none' ? null : response.data, function(err, data, status, headers, host) { if (response && !err) { response.data = { data: data, status: status, headers: headers, host: host }; instance.send2(response); } else if (err) instance.error(err, response); }, cookies || cookies2, headers); } }; instance.reconfigure = function() { var options = instance.options; can = options.url && options.url && options.method && options.stringify ? true : false; instance.status(can ? '' : 'Not configured', can ? undefined : 'red'); if (!can) return; flags = []; flags.push(options.method.toLowerCase()); options.stringify === 'json' && flags.push('json'); options.stringify === 'raw' && flags.push('raw'); options.keepalive && flags.push('keepalive'); !options.nodns && flags.push('dnscache'); if (options.persistentcookies) { flags.push('cookies'); cookies2 = {}; } else cookies2 = null; }; instance.on('options', instance.reconfigure); instance.reconfigure(); };