All files / src/utils cookie.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1912x   12x 32x 32x 32x 32x 9x 3x     32x 32x 3x     32x    
import { parse } from 'cookie'
 
export function filterCookies(headers: Headers, filterFunc: (key: string) => boolean): Headers {
  const newHeaders = new Headers(headers)
  const cookie = parse(headers.get('cookie') || '')
  const filteredCookieList = []
  for (const cookieName in cookie) {
    if (filterFunc(cookieName)) {
      filteredCookieList.push(`${cookieName}=${cookie[cookieName]}`)
    }
  }
  newHeaders.delete('cookie')
  if (filteredCookieList.length > 0) {
    newHeaders.set('cookie', filteredCookieList.join('; '))
  }
 
  return newHeaders
}