MCPcopy
hub / github.com/tinyhttp/tinyhttp / parse

Function parse

packages/forwarded/src/index.ts:18–47  ·  view source on GitHub ↗
(header: string)

Source from the content-addressed store, hash-verified

16 * Parse the X-Forwarded-For header.
17 */
18export function parse(header: string) {
19 let end = header.length
20 const list = []
21 let start = header.length
22
23 // gather addresses, backwards
24 for (let i = header.length - 1; i >= 0; i--) {
25 switch (header.charCodeAt(i)) {
26 case 0x20 /* */:
27 if (start === end) {
28 start = end = i
29 }
30 break
31 case 0x2c /* , */:
32 if (start !== end) {
33 list.push(header.substring(start, end))
34 }
35 start = end = i
36 break
37 default:
38 start = i
39 break
40 }
41 }
42
43 // final address
44 if (start !== end) list.push(header.substring(start, end))
45
46 return list
47}

Callers 1

forwardedFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected