diff options
| author | soruly <[email protected]> | 2020-08-09 15:21:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-09 15:21:46 +0800 |
| commit | 88ead4626cc9d6b89d24f2beb81a3ac4f9a6f9af (patch) | |
| tree | 1917a57ed5e557d1e2832fb663c08f469b592026 /api | |
| parent | Support Content-Type detection (diff) | |
| download | trace.moe-image-proxy-88ead4626cc9d6b89d24f2beb81a3ac4f9a6f9af.tar.xz trace.moe-image-proxy-88ead4626cc9d6b89d24f2beb81a3ac4f9a6f9af.zip | |
Cache responses in edge server
Diffstat (limited to 'api')
| -rw-r--r-- | api/image-proxy.ts | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/api/image-proxy.ts b/api/image-proxy.ts index 3bd88c8..334056d 100644 --- a/api/image-proxy.ts +++ b/api/image-proxy.ts @@ -28,6 +28,7 @@ export default async (request: NowRequest, response: NowResponse) => { if (["image", "video"].includes(res.headers.get("Content-Type").split("/")[0].toLowerCase())) { response.setHeader("Content-Type", res.headers.get("Content-Type")); + response.setHeader("Cache-Control", "s-maxage=86400"); } else if (res.headers.get("Content-Type").toLowerCase() === "application/octet-stream") { const match = imageURL.match(/\.(\w{3,4})($|\?)/); if (!match) return response.status(400).send("Error: Cannot determine Content-Type"); @@ -45,6 +46,7 @@ export default async (request: NowRequest, response: NowResponse) => { }[match[1]]; if (!contentType) return response.status(400).send("Error: Unknown Content-Type"); response.setHeader("Content-Type", contentType); + response.setHeader("Cache-Control", "s-maxage=86400"); } else { return response.status(400).send("Error: Unsupported Content-Type"); } |