Skip to content

Commit

Permalink
Merge 68f0f01 into ce72c8e
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambie committed Nov 19, 2018
2 parents ce72c8e + 68f0f01 commit 50e4be8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config.js
Expand Up @@ -660,6 +660,11 @@ const schema = {
format: Number,
default: 10,
allowDomainOverride: true
},
maxSockets: {
doc: 'Determines how many concurrent sockets the HTTP/HTTPS agents can have open per origin',
format: Number,
default: null
}
},
defaultFiles: {
Expand Down
2 changes: 1 addition & 1 deletion dadi/lib/handlers/image.js
Expand Up @@ -64,7 +64,7 @@ const IMAGE_PARAMETERS = [
{ name: 'strip', aliases: ['s'] },
{ name: 'rotate', aliases: ['r'] },
{ name: 'flip', aliases: ['fl'] },
{ name: 'progressive', aliases: ['pg'], default: 'true' }
{ name: 'progressive', aliases: ['pg'] }
]

/**
Expand Down
15 changes: 14 additions & 1 deletion dadi/lib/storage/http.js
Expand Up @@ -9,6 +9,14 @@ const url = require('url')
const urljoin = require('url-join')
const Missing = require(path.join(__dirname, '/missing'))

let httpKeepAliveAgent = new http.Agent({ keepAlive: true })
let httpsKeepAliveAgent = new https.Agent({ keepAlive: true })

if (config.get('http.maxSockets')) {
http.globalAgent.maxSockets = config.get('http.maxSockets')
https.globalAgent.maxSockets = config.get('http.maxSockets')
}

const HTTPStorage = function ({assetType = 'assets', domain, url}) {
let isExternalURL = url.indexOf('http:') === 0 ||
url.indexOf('https:') === 0
Expand Down Expand Up @@ -45,11 +53,14 @@ HTTPStorage.prototype.get = function ({
? https
: http

let agent = parsedUrl.protocol === 'https:' ? httpsKeepAliveAgent : httpKeepAliveAgent

requestFn.get({
protocol: parsedUrl.protocol,
agent,
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port,
protocol: parsedUrl.protocol,
headers: {
'User-Agent': 'DADI CDN'
}
Expand All @@ -64,6 +75,8 @@ HTTPStorage.prototype.get = function ({
})

res.on('end', () => {
agent.destroy()

return resolve(streamifier.createReadStream(Buffer.concat(buffers)))
})
} else {
Expand Down

0 comments on commit 50e4be8

Please sign in to comment.