function addClientInfo(socket, chunk, statusLine, clientIp, clientPort) { var len = Buffer.byteLength(statusLine); chunk = chunk.slice(len); statusLine += '\r\n' + config.CLIENT_INFO_HEAD + ': ' + clientIp + ',' + clientPort; var clientId = socket.headers[config.CLIENT_ID_HEADER]; if (clientId) { statusLine += '\r\n' + config.TEMP_CLIENT_ID_HEADER + ': ' + clientId; } var tunnelData = socket.headers[config.TUNNEL_DATA_HEADER]; if (tunnelData) { statusLine += '\r\n' + config.TEMP_TUNNEL_DATA_HEADER + ': ' + tunnelData; } return Buffer.concat([Buffer.from(statusLine), chunk]); }
sessions.map(function(item, index) { item.req.url = item.url; var req = util.getReqRaw(item.req); var res = !item.res || item.res.statusCode == null ? Buffer.from('') : util.getResRaw(item.res); var name = getName(); item.index = index; zip.add('raw/' + name + '_c.txt', req); zip.add('raw/' + name + '_m.xml', Buffer.from(getFiddler2Meta(item))); zip.add('raw/' + name + '_s.txt', res); zip.add('raw/' + name + '_whistle.json', Buffer.from(JSON.stringify({ realUrl: item.realUrl, rules: item.rules, frames: item.frames, useHttp: item.useHttp, httpsTime: item.httpsTime, useH2: item.useH2, mark: item.mark, trailers: item.res && item.res.trailers, rawTrailerNames: item.res && item.res.rawTrailerNames }))); });
function joinData(list, isText) { if (!list || !list.length) { return ''; } if (isText) { return list.filter(noop).join('\r\n'); } var result = []; list.forEach(function(buf) { if (buf) { buf = Buffer.isBuffer(buf) ? buf : Buffer.from(buf + ''); result.push(buf, CRLF); } }); result.pop(); return result.length ? Buffer.concat(result) : ''; }
var pushFrame = function(reqId, data, opts, isClient) { if (data == null) { return; } if (!Buffer.isBuffer(data)) { try { if (typeof data !== 'string') { data = JSON.stringify(data); } data = Buffer.from(data); } catch(e) { data = null; } } if (!data) { return; } opts = getFrameOpts(opts); opts.reqId = reqId; opts.frameId = getFrameId(); opts.isClient = isClient; opts.length = data.length; if (opts.length > MAX_BUF_LEN) { data = data.slice(0, MAX_BUF_LEN); } opts.base64 = data.toString('base64'); addFrame(opts); }
function toBuffer(buf, charset) { if (buf == null || Buffer.isBuffer(buf)) { return buf; } buf += ''; if (charset && typeof charset === 'string' && !UTF8_RE.test(charset)) { try { charset = charset.toLowerCase(); if (charset === 'base64') { return Buffer.from(buf, 'base64'); } return iconv.encode(buf, charset); } catch (e) {} } return Buffer.from(buf); }