silverwolf-x/project / packages /next /src /server /lib /streaming-metadata.ts
silverwolf-x's picture
download
raw
984 Bytes
import {
getBotType,
HTML_LIMITED_BOT_UA_RE_STRING,
} from '../../shared/lib/router/utils/is-bot'
import type { BaseNextRequest } from '../base-http'
let cachedPattern: string | undefined
let cachedRegex: RegExp | undefined
export function shouldServeStreamingMetadata(
userAgent: string,
htmlLimitedBots: string | undefined
): boolean {
const pattern = htmlLimitedBots || HTML_LIMITED_BOT_UA_RE_STRING
if (cachedPattern !== pattern) {
cachedPattern = pattern
cachedRegex = new RegExp(pattern, 'i')
}
// Only block metadata for HTML-limited bots
if (userAgent && cachedRegex!.test(userAgent)) {
return false
}
return true
}
// When the request UA is a html-limited bot, we should do a dynamic render.
// In this case, postpone state is not sent.
export function isHtmlBotRequest(req: {
headers: BaseNextRequest['headers']
}): boolean {
const ua = req.headers['user-agent'] || ''
const botType = getBotType(ua)
return botType === 'html'
}

Xet Storage Details

Size:
984 Bytes
·
Xet hash:
2850b26e0e3c40f2ab312a7839cbde1f2160cd06be15a2e4881f064332e37995

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.