MCPcopy
hub / github.com/vercel/next.js / getConditionValue

Function getConditionValue

packages/next-routing/src/matchers.ts:43–76  ·  view source on GitHub ↗

* Extracts the value for a RouteHas condition from the request context

(
  condition: RouteHas,
  url: URL,
  headers: Headers
)

Source from the content-addressed store, hash-verified

41 * Extracts the value for a RouteHas condition from the request context
42 */
43function getConditionValue(
44 condition: RouteHas,
45 url: URL,
46 headers: Headers
47): string | undefined {
48 switch (condition.type) {
49 case 'header':
50 return headers.get(condition.key) || undefined
51 case 'cookie': {
52 const cookieHeader = headers.get('cookie')
53 if (!cookieHeader) return undefined
54
55 // Parse cookies
56 const cookies = cookieHeader.split(';').reduce(
57 (acc, cookie) => {
58 const [key, ...valueParts] = cookie.trim().split('=')
59 if (key) {
60 acc[key] = valueParts.join('=')
61 }
62 return acc
63 },
64 {} as Record<string, string>
65 )
66
67 return cookies[condition.key]
68 }
69 case 'query':
70 return url.searchParams.get(condition.key) || undefined
71 case 'host':
72 return url.hostname
73 default:
74 return ''
75 }
76}
77
78/**
79 * Normalizes a capture key to only contain a-zA-Z characters

Callers 2

checkHasConditionsFunction · 0.85
checkMissingConditionsFunction · 0.85

Calls 5

reduceMethod · 0.80
splitMethod · 0.80
trimMethod · 0.80
getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…