https://kotlinlang.org logo
#http4k
Title
# http4k
a

andyg

05/08/2020, 7:46 AM
re: cookies. I have a list of Response objects from the same domain, now I am trying to replicate the client state at the end, specifically the cookies. The basic logic would say to loop through each Response, and for each Cookie either add new or overwrite, as appropriate. What's the most efficient or easiest way to do this in 4k? loop and create a simple list of k/v pairs? Use BasicCookieStorage and map the Response's cookie to LocalCookie? Use a Filter and send each Response through it? Something else? Thank you.
I built the following extension to Request, if someone else has a similar requirement:
fun Request.addCookies(responses: List<Response>) : Request {
return responses.fold(this, { request, response ->
response.cookies().fold(this, { req, c -> req.cookie(c.name, c.value) })
})
}
15 Views