pass HTTP metadata in S3/R2 Source impls

This commit is contained in:
Brandon Liu
2022-11-22 14:43:15 +08:00
parent a619aa84e2
commit f457724da1
3 changed files with 15 additions and 3 deletions

View File

@@ -866,6 +866,8 @@ export class PMTiles {
d_l = entry.length; d_l = entry.length;
} }
} else { } else {
// TODO: We should in fact return a valid RangeResponse
// with empty data, but filled in cache control / expires headers
return undefined; return undefined;
} }
} }

View File

@@ -100,7 +100,12 @@ class S3Source implements Source {
const arr = await resp.Body!.transformToByteArray(); const arr = await resp.Body!.transformToByteArray();
return { data: arr.buffer }; return {
data: arr.buffer,
etag: resp.ETag,
expires: resp.Expires?.toISOString(),
cacheControl: resp.CacheControl,
};
} }
} }
@@ -156,7 +161,7 @@ export const handler = async (
// TODO: metadata and TileJSON // TODO: metadata and TileJSON
if (process.env.CORS) { if (process.env.CORS) {
headers['Access-Control-Allow-Origin'] = process.env.CORS; headers["Access-Control-Allow-Origin"] = process.env.CORS;
} }
const source = new S3Source(name); const source = new S3Source(name);

View File

@@ -109,7 +109,12 @@ class R2Source implements Source {
} }
const o = resp as R2ObjectBody; const o = resp as R2ObjectBody;
const a = await o.arrayBuffer(); const a = await o.arrayBuffer();
return { data: a, etag: o.etag }; return {
data: a,
etag: o.etag,
cacheControl: o.httpMetadata?.cacheControl,
expires: o.httpMetadata?.cacheExpiry?.toISOString(),
};
} }
} }