Add Response.withHeaders for adding more than one header at once.

This commit is contained in:
Dillon Kearns 2022-03-07 08:55:03 -08:00
parent 9f788d8aba
commit 032c710c74
2 changed files with 14 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@ module Server.Response exposing
, emptyBody, body, bytesBody, base64Body
, render
, map
, withHeader, withStatusCode, withSetCookieHeader
, withHeader, withHeaders, withStatusCode, withSetCookieHeader
, toJson
)
@ -49,7 +49,7 @@ You can use `withHeader` and `withStatusCode` to customize either type of Respon
## Amending Responses
@docs withHeader, withStatusCode, withSetCookieHeader
@docs withHeader, withHeaders, withStatusCode, withSetCookieHeader
## Internals
@ -228,6 +228,17 @@ withHeader name value serverResponse =
ServerResponse { response | headers = ( name, value ) :: response.headers }
{-| -}
withHeaders : List ( String, String ) -> Response data -> Response data
withHeaders headers serverResponse =
case serverResponse of
RenderPage response data ->
RenderPage { response | headers = headers ++ response.headers } data
ServerResponse response ->
ServerResponse { response | headers = headers ++ response.headers }
{-| -}
withSetCookieHeader : SetCookie -> Response data -> Response data
withSetCookieHeader cookie response =