mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
add ETag and cache-control headers for 200 responses (#231)
* add etag and cache control headers for 200 responses * fixup eTag -> ETag
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
import { pmtiles_path, tile_path, tileJSON } from "../../shared/index";
|
||||
|
||||
import zlib from "zlib";
|
||||
import { createHash } from "crypto"
|
||||
|
||||
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { NodeHttpHandler } from "@aws-sdk/node-http-handler";
|
||||
@@ -206,6 +207,9 @@ export const handlerRaw = async (
|
||||
data = tilePostprocess(data, header.tileType);
|
||||
}
|
||||
|
||||
headers["Cache-Control"] = `public, max-age=${process.env.CACHE_MAX_AGE || 86400}`;
|
||||
headers["ETag"] = `"${createHash("sha256").update(Buffer.from(data)).digest("hex")}"`
|
||||
|
||||
if (is_api_gateway) {
|
||||
// this is wasted work, but we need to force API Gateway to interpret the Lambda response as binary
|
||||
// without depending on clients sending matching Accept: headers in the request.
|
||||
@@ -235,7 +239,6 @@ export const handlerRaw = async (
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return apiResp(404, "Invalid URL", false, headers);
|
||||
};
|
||||
|
||||
export const handler = async (
|
||||
|
||||
Reference in New Issue
Block a user