MCPcopy Create free account
hub / github.com/nodejs/undici / splitCacheControlHeaderValue

Function splitCacheControlHeaderValue

lib/util/cache.js:53–102  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

51}
52
53function splitCacheControlHeaderValue (value) {
54 const directives = []
55 let start = 0
56 let quoteStart = -1
57 let inQuote = false
58 let escaped = false
59
60 for (let i = 0; i < value.length; i++) {
61 if (inQuote) {
62 if (escaped) {
63 escaped = false
64 } else if (value[i] === '\\') {
65 escaped = true
66 } else if (value[i] === '"') {
67 inQuote = false
68 quoteStart = -1
69 }
70 } else if (value[i] === '"') {
71 inQuote = true
72 quoteStart = i
73 } else if (value[i] === ',') {
74 directives.push({ value: value.substring(start, i), fromMalformedQuote: false })
75 start = i + 1
76 }
77 }
78
79 if (!inQuote) {
80 directives.push({ value: value.substring(start), fromMalformedQuote: false })
81 return directives
82 }
83
84 const tail = value.substring(start)
85 const quoteOffset = quoteStart - start
86 let tailStart = 0
87 for (let i = 0; i < tail.length; i++) {
88 if (tail[i] === ',') {
89 directives.push({
90 value: tail.substring(tailStart, i),
91 fromMalformedQuote: tailStart > quoteOffset
92 })
93 tailStart = i + 1
94 }
95 }
96
97 directives.push({
98 value: tail.substring(tailStart),
99 fromMalformedQuote: tailStart > quoteOffset
100 })
101 return directives
102}
103
104function markInvalidCacheControlDirective (directives, key) {
105 let invalidDirectives = directives[kInvalidCacheControlDirectives]

Callers 1

parseCacheControlHeaderFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected