MCPcopy
hub / github.com/tinyhttp/tinyhttp / append

Function append

packages/res/src/append.ts:6–22  ·  view source on GitHub ↗
(res: Response)

Source from the content-addressed store, hash-verified

4type Res = Pick<S, 'getHeader' | 'setHeader'>
5
6export const append = <Response extends Res = Res>(res: Response) => (
7 field: string,
8 value: string | number | string[]
9): Response => {
10 const prevVal = getResponseHeader(res)(field)
11 let newVal = value
12
13 if (prevVal && typeof newVal !== 'number' && typeof prevVal !== 'number') {
14 newVal = Array.isArray(prevVal)
15 ? prevVal.concat(newVal)
16 : Array.isArray(newVal)
17 ? [prevVal].concat(newVal)
18 : [prevVal, newVal]
19 }
20 setHeader(res)(field, newVal)
21 return res
22}

Callers 3

extendMiddlewareFunction · 0.90
setCookieFunction · 0.90
res.test.tsFile · 0.90

Calls 2

getResponseHeaderFunction · 0.90
setHeaderFunction · 0.90

Tested by

no test coverage detected