Skip to content

Commit

Permalink
feat: add logging to understand impact of trailing slash 308s (#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
orinokai authored Jan 21, 2025
1 parent aab8803 commit e77b98a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/run/handlers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default async (request: Request) => {

await adjustDateHeader({ headers: response.headers, request, span, tracer, requestContext })

setCacheControlHeaders(response, request, requestContext)
setCacheControlHeaders(response, request, requestContext, nextConfig)
setCacheTagsHeaders(response.headers, requestContext)
setVaryHeaders(response.headers, request, nextConfig)
setCacheStatusHeader(response.headers)
Expand Down
10 changes: 9 additions & 1 deletion src/run/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextConfigComplete } from 'next/dist/server/config-shared.js'

import { encodeBlobKey } from '../shared/blobkey.js'

import type { RequestContext } from './handlers/request-context.cjs'
import { getLogger, RequestContext } from './handlers/request-context.cjs'
import type { RuntimeTracer } from './handlers/tracer.cjs'
import { getRegionalBlobStore } from './regional-blob-store.cjs'

Expand Down Expand Up @@ -216,6 +216,7 @@ export const setCacheControlHeaders = (
{ headers, status }: Response,
request: Request,
requestContext: RequestContext,
nextConfig: NextConfigComplete,
) => {
if (
typeof requestContext.routeHandlerRevalidate !== 'undefined' &&
Expand All @@ -234,6 +235,13 @@ export const setCacheControlHeaders = (
return
}

// temporary diagnostic to evaluate number of trailing slash redirects
if (status === 308 && request.url.endsWith('/') !== nextConfig.trailingSlash) {
getLogger()
.withFields({ trailingSlash: nextConfig.trailingSlash })
.log('NetlifyHeadersHandler.trailingSlashRedirect')
}

if (status === 404 && request.url.endsWith('.php')) {
// temporary CDN Cache Control handling for bot probes on PHP files
// https://linear.app/netlify/issue/FRB-1344/prevent-excessive-ssr-invocations-due-to-404-routes
Expand Down

0 comments on commit e77b98a

Please sign in to comment.