Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var shasum = crypto.createHash('sha1');
shasum.update([process.env.agentid || os.hostname(), token, nonce, id].join(''));
var sign = shasum.digest('hex');
var url = 'http://' + server + '/files/' + id + '?nonce=' + nonce + '&sign=' + sign + '&type=' + type;
var gateway = process.env.GATEWAY;
if (gateway) {
// upload to gateway
url = 'http://' + gateway + '/file?target=' + encodeURIComponent(url);
}
var agent = false;
if (process.env.http_proxy) {
var parts = process.env.http_proxy.split(':');
agent = tunnel.httpOverHttp({
proxy: {
host: parts[0],
port: parts[1]
}
});
}
var opts = {
dataType: 'json',
type: 'POST',
timeout: 60000 * 20, // 20分钟超时
headers: form.headers(),
stream: form,
agent: agent
};
var uploadToken = putPolicy.uploadToken(mac);
var config = new qiniu.conf.Config();
// config.zone = qiniu.zone.Zone_z0;
// config.useHttpsDomain = true;
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();
// 设置HTTP(s)代理服务器,这里可以参考:https://github.com/request/tunnel-agent
// 有几个方法:
// exports.httpOverHttp = httpOverHttp
// exports.httpsOverHttp = httpsOverHttp
// exports.httpOverHttps = httpOverHttps
// exports.httpsOverHttps = httpsOverHttps
var proxyAgent = tunnel.httpOverHttp({
proxy: {
host: 'localhost',
port: 8888
}
});
qiniu.conf.RPC_HTTP_AGENT = proxyAgent;
// qiniu.conf.RPC_HTTPS_AGENT = proxyAgent;
// 以代理方式上传
formUploader.put(uploadToken, null, 'hello', putExtra, function (respErr,
respBody, respInfo) {
if (respErr) {
throw respErr;
}
var hostname = urlObject.hostname || 'localhost';
if (requestIsSSL) {
if (protocol === 'http:') {
if (!httpsOverHttpAgent) {
httpsOverHttpAgent = tunnelAgent.httpsOverHttp({
proxy: {
host: hostname,
port: port
}
});
}
return httpsOverHttpAgent
} else {
if (!httpsOverHttpsAgent) {
httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
proxy: {
host: hostname,
port: port
}
});
}
return httpsOverHttpsAgent
}
} else {
if (protocol === 'http:') {
// if (!httpOverHttpAgent) {
// httpOverHttpAgent = tunnelAgent.httpOverHttp({
// proxy: {
// host: hostname,
// port: port
// }
return httpsOverHttpsAgent
}
} else {
if (protocol === 'http:') {
// if (!httpOverHttpAgent) {
// httpOverHttpAgent = tunnelAgent.httpOverHttp({
// proxy: {
// host: hostname,
// port: port
// }
// });
// }
return false
} else {
if (!httpOverHttpsAgent) {
httpOverHttpsAgent = tunnelAgent.httpOverHttps({
proxy: {
host: hostname,
port: port
}
});
}
return httpOverHttpsAgent
}
}
}
server.listen(0, function() {
var tunnel = require('tunnel-agent');
var agentSettings = {
proxy: {
host: server.address().host,
port: server.address().port
}
};
var proxyClient = algoliasearch(appId, apiKey, {
httpAgent: tunnel.httpsOverHttp(agentSettings)
});
var proxyIndex = proxyClient.initIndex(indexName);
proxyIndex
.browse()
.then(end)
.then(null, _.bind(t.error, t));
function end(content) {
server.close();
proxyClient.destroy();
t.ok(content.hits.length, 'We got some content');
}
});
}
export function assign (reqOpts: RequestOptions): void {
const proxy = reqOpts.proxy;
if (proxy && reqOpts.protocol === 'https:') {
reqOpts.agent = tunnel.httpsOverHttp({
proxy,
rejectUnauthorized: false
});
return;
}
let type = '';
if (reqOpts.protocol === 'http:')
type = TYPE.HTTP;
else if (ssl3HostCache.get(reqOpts.host))
type = TYPE.SSL3;
else
}
var options = assign({
proxy: {
host: this._proxyUri.hostname,
port: this._proxyUri.port || this.DEFAULT_PORTS[this._proxyUri.protocol],
proxyAuth: this._proxyUri.auth,
headers: assign({ host: this.endpoint.host }, proxy.headers)
}
}, this._dispatcher.tls);
if (this._proxySecure) {
assign(options.proxy, proxy.tls);
this._tunnel = tunnel.httpsOverHttps(options);
} else {
this._tunnel = tunnel.httpsOverHttp(options);
}
},
return new Promise(function (fulfill, reject) {
let httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
let agent;
if (httpsProxy) {
cli.hush(`proxy set to ${httpsProxy}`);
let proxy = url.parse(httpsProxy);
agent = tunnel.httpsOverHttp({
proxy: {
host: proxy.hostname,
port: proxy.port || 8080
}
});
} else {
agent = new https.Agent();
}
let requestOptions = url.parse(urlStr);
requestOptions.agent = agent;
let req = https.request(requestOptions, function (res) {
if (res.statusCode > 200 || res.statusCode >= 300) return reject(new Error(res.body));
res.pipe(fs.createWriteStream(tmpPath, opts));
res.on('end', fulfill);
util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
var urlObject = url.parse(externalProxyUrl);
var protocol = urlObject.protocol || 'http:';
var port = urlObject.port;
if (!port) {
port = protocol === 'http:' ? 80 : 443;
}
var hostname = urlObject.hostname || 'localhost';
if (requestIsSSL) {
if (protocol === 'http:') {
if (!httpsOverHttpAgent) {
httpsOverHttpAgent = tunnelAgent.httpsOverHttp({
proxy: {
host: hostname,
port: port
}
});
}
return httpsOverHttpAgent
} else {
if (!httpsOverHttpsAgent) {
httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
proxy: {
host: hostname,
port: port
}
});
}
var config = require('../config');
var httpAgent;
var httpsAgent;
if (config.httpProxy) {
var tunnel = require('tunnel-agent');
var urlinfo = urlparse(config.httpProxy);
if (urlinfo.protocol === 'http:') {
httpAgent = tunnel.httpOverHttp({
proxy: {
host: urlinfo.hostname,
port: urlinfo.port
}
});
httpsAgent = tunnel.httpsOverHttp({
proxy: {
host: urlinfo.hostname,
port: urlinfo.port
}
});
} else if (urlinfo.protocol === 'https:') {
httpAgent = tunnel.httpOverHttps({
proxy: {
host: urlinfo.hostname,
port: urlinfo.port
}
});
httpsAgent = tunnel.httpsOverHttps({
proxy: {
host: urlinfo.hostname,
port: urlinfo.port