Skip to content

Commit

Permalink
fix(cache): use lowercase headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 18, 2022
1 parent cbe0e91 commit 9eb5769
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"fs-extra": "^10.1.0",
"globby": "^13.1.2",
"gzip-size": "^7.0.0",
"h3": "^0.8.3",
"h3": "^0.8.4",
"hookable": "^5.4.1",
"http-proxy": "^1.18.1",
"is-primitive": "^3.0.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export function defineCachedEventHandler <T=any> (

// Collect cachable headers
const headers = event.res.getHeaders()
headers.Etag = `W/"${hash(body)}"`
headers['Last-Modified'] = new Date().toUTCString()
headers.etag = headers.Etag || headers.etag || `W/"${hash(body)}"`
headers['last-modified'] = headers['Last-Modified'] || headers['last-modified'] || new Date().toUTCString()
const cacheControl = []
if (opts.swr) {
if (opts.maxAge) {
Expand All @@ -189,7 +189,7 @@ export function defineCachedEventHandler <T=any> (
cacheControl.push(`max-age=${opts.maxAge}`)
}
if (cacheControl.length) {
headers['Cache-Control'] = cacheControl.join(', ')
headers['cache-control'] = cacheControl.join(', ')
}

// Create cache entry for response
Expand Down Expand Up @@ -222,7 +222,7 @@ export function defineCachedEventHandler <T=any> (

// Check for cache headers
if (handleCacheHeaders(event, {
modifiedTime: new Date(response.headers['Last-Modified'] as string),
modifiedTime: new Date(response.headers['last-modified'] as string),
etag: response.headers.etag as string,
maxAge: opts.maxAge
})) {
Expand Down

0 comments on commit 9eb5769

Please sign in to comment.