Skip to content

Commit

Permalink
refactor: compute etag just once
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Jun 20, 2018
1 parent 18f42c0 commit 7142039
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dadi/lib/controller/index.js
Expand Up @@ -62,12 +62,14 @@ const Controller = function (router) {
// receive the concatenated buffer and send the response
// unless the etag hasn't changed, then send 304 and end the response
function sendBuffer (buffer) {
let etagResult = etag(buffer)

res.setHeader('Content-Length', contentLength)
res.setHeader('ETag', etag(buffer))
res.setHeader('ETag', etagResult)

if (req.headers.range) {
res.sendSeekable(buffer)
} else if (req.headers['if-none-match'] === etag(buffer) && handler.getContentType() !== 'application/json') {
} else if (req.headers['if-none-match'] === etagResult && handler.getContentType() !== 'application/json') {
res.statusCode = 304
res.end()
} else {
Expand Down

0 comments on commit 7142039

Please sign in to comment.