Commit 93546306 authored by nanahira's avatar nanahira

add etag to cacheResult

parent 13e4c829
Pipeline #40982 passed with stages
in 2 minutes and 56 seconds
......@@ -3,6 +3,7 @@ import { UpdateService } from './update.service';
import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { DepotDto } from '../dto/Depot.dto';
import { Response } from 'express';
import { createHash } from 'crypto';
@Controller('update')
@ApiTags('update')
......@@ -17,7 +18,9 @@ export class UpdateController {
private async cacheResult<T>(res: Response, prom: Promise<T>) {
const result = await prom;
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
const hash = createHash('sha512').update(JSON.stringify(result)).digest('hex');
res.setHeader('ETag', `"${hash}"`); // minio-compatibility requires quotes
if (res.getHeader('Cache-Control') === undefined) res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
return result;
}
......
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