mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2025-06-16 20:31:29 -07:00
Handle Etag and If-none-match headers and 304 responses
This commit is contained in:
parent
a674d6a79c
commit
1b95c4c794
2 changed files with 29 additions and 4 deletions
18
server.js
18
server.js
|
@ -19,11 +19,21 @@ function getFox (req, res, version) {
|
|||
let width = parseInt(req.params.width) || 400
|
||||
if (width > 400) width = 400
|
||||
const seed = sanitize(req.params.seed) || uuid()
|
||||
const etag = `W/${seed}`
|
||||
const contentType = 'image/png'
|
||||
|
||||
res.set('Cache-Control', 'public; max-age=' + cacheTimeout)
|
||||
res.set('Content-Type', contentType)
|
||||
res.set('Etag', etag)
|
||||
|
||||
if (req.headers['if-none-match'] === etag) {
|
||||
res.status(304).end('')
|
||||
return
|
||||
}
|
||||
|
||||
const canvas = composeImage(width, width, seed, version)
|
||||
const buffer = canvas.toBuffer('image/png')
|
||||
res.set('Cache-Control', 'max-age=' + cacheTimeout)
|
||||
res.set('Content-length', buffer.length)
|
||||
res.type('png')
|
||||
const buffer = canvas.toBuffer(contentType)
|
||||
res.set('Content-Length', buffer.length)
|
||||
res.end(buffer, 'binary')
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue