Commit e32deed1 authored by Sebastiaan Deckers's avatar Sebastiaan Deckers 馃悜

refactor: inlining push promise creation

parent 23995998
......@@ -26,24 +26,21 @@ async function resolveDependencies (request, response, next) {
':scheme': 'https',
':authority': request.authority
}
const pushStream = (headers, weight) => new Promise((resolve, reject) => {
const { stream } = response
stream.pushStream(headers, (error, stream) => {
if (error) return reject(error)
else resolve(stream)
})
if (weight !== HTTP2_PRIORITY_DEFAULT) {
stream.priority({ weight, silent: true })
}
})
const pushPromises = []
for (const [relative, priority] of dependencies) {
const dependency = request.fileIndex.relative.get(relative)
headers[':path'] = dependency.pathname
response.log.info(`PUSH ${baseUrl}${dependency.pathname}`)
const pushPromise = pushStream(headers, priority)
.then((pushResponse) => ({ pushResponse, dependency }))
pushPromises.push(pushPromise)
pushPromises.push(new Promise((resolve, reject) => {
const dependency = request.fileIndex.relative.get(relative)
response.log.info(`PUSH ${baseUrl}${dependency.pathname}`)
headers[':path'] = dependency.pathname
const { stream } = response
stream.pushStream(headers, (error, stream) => {
if (error) return reject(error)
else resolve({ pushResponse: stream, dependency })
})
if (priority !== HTTP2_PRIORITY_DEFAULT) {
stream.priority({ weight: priority, silent: true })
}
}))
}
request.pushResponses = await Promise.all(pushPromises)
} else if (request.httpVersionMajor === 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment