Skip to content

Commit

Permalink
feat: appendHeader utility
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 15, 2020
1 parent 306cab2 commit 84be904
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ export function sendRedirect (res: ServerResponse, location: string, code = 302)
defaultContentType(res, MIMES.html)
res.end(location)
}

export function appendHeader (res: ServerResponse, name: string, value: string): void {
let current = res.getHeader(name)

if (!current) {
return res.setHeader(name, value)
}

if (!Array.isArray(current)) {
current = [current.toString()]
}

res.setHeader(name, current.concat(value))
}

0 comments on commit 84be904

Please sign in to comment.