mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-20 19:51:09 +10:00
feat: add etag to object response
This commit is contained in:
@ -11,6 +11,16 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!object)
|
||||
throw createError({ statusCode: 404, statusMessage: "Object not found" });
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
|
||||
const etagValue = h3.headers.get("If-None-Match");
|
||||
if (etagValue !== null) {
|
||||
// would compare if etag is valid, but objects should never change
|
||||
setResponseStatus(h3, 304);
|
||||
return null;
|
||||
}
|
||||
|
||||
// just return object id has etag since object should never change
|
||||
setHeader(h3, "ETag", id);
|
||||
setHeader(h3, "Content-Type", object.mime);
|
||||
setHeader(
|
||||
h3,
|
||||
|
||||
Reference in New Issue
Block a user