Skip to content

Commit

Permalink
fix: set user agent for purge requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Dec 19, 2024
1 parent f00b542 commit 4a26b91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
45 changes: 10 additions & 35 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@netlify/edge-bundler": "^12.2.3",
"@netlify/edge-functions": "^2.11.0",
"@netlify/eslint-config-node": "^7.0.1",
"@netlify/functions": "^2.8.2",
"@netlify/functions": "^3.0.0",
"@netlify/serverless-functions-api": "^1.30.1",
"@netlify/zip-it-and-ship-it": "^9.41.0",
"@opentelemetry/api": "^1.8.0",
Expand Down
19 changes: 12 additions & 7 deletions src/run/handlers/cache.cts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { type Span } from '@opentelemetry/api'
import type { PrerenderManifest } from 'next/dist/build/index.js'
import { NEXT_CACHE_TAGS_HEADER } from 'next/dist/lib/constants.js'

import { name as nextRuntimePkgName, version as nextRuntimePkgVersion } from '../../../package.json'
import {
type CacheHandlerContext,
type CacheHandlerForMultipleVersions,
Expand All @@ -30,6 +31,8 @@ type TagManifest = { revalidatedAt: number }

type TagManifestBlobCache = Record<string, Promise<TagManifest>>

const purgeCacheUserAgent = `${nextRuntimePkgName}@${nextRuntimePkgVersion}`

export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
options: CacheHandlerContext
revalidatedTags: string[]
Expand Down Expand Up @@ -347,12 +350,14 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
const tag = `_N_T_${key === '/index' ? '/' : encodeURI(key)}`
getLogger().debug(`Purging CDN cache for: [${tag}]`)
requestContext.trackBackgroundWork(
purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => {
// TODO: add reporting here
getLogger()
.withError(error)
.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`)
}),
purgeCache({ tags: tag.split(/,|%2c/gi), userAgent: purgeCacheUserAgent }).catch(
(error) => {
// TODO: add reporting here
getLogger()
.withError(error)
.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`)
},
),
)
}
}
Expand Down Expand Up @@ -393,7 +398,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
}),
)

await purgeCache({ tags }).catch((error) => {
await purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => {
// TODO: add reporting here
getLogger()
.withError(error)
Expand Down

0 comments on commit 4a26b91

Please sign in to comment.