Skip to content

Commit 3dc13dd

Browse files
987Nabilmhodovaniuk
authored andcommitted
Add addCookie and addCookies to Request/Response (zio#3365) (zio#3410)
1 parent 4e1695f commit 3dc13dd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

zio-http/jvm/src/test/scala/zio/http/ServerRuntimeSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object ServerRuntimeSpec extends RoutesRunnableSpec {
116116
.zipRight(routes.deploy.body.run(path = Path.root / "test", method = Method.GET))
117117
.flatMap(_.asString(Charsets.Utf8))
118118
.map(b => assertTrue(b == "ok")) *> ref.get.map { v => assertTrue(v == 1) }
119-
}
119+
} @@ TestAspect.flaky
120120
}
121121
.provide(
122122
Scope.default,

zio-http/shared/src/main/scala/zio/http/Request.scala

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ final case class Request(
6161

6262
def addLeadingSlash: Request = self.copy(url = url.addLeadingSlash)
6363

64+
def addCookie(cookie: Cookie.Request) =
65+
updateHeaders(_.addHeader(Header.Cookie(NonEmptyChunk(cookie))))
66+
67+
def addCookies(cookie: Cookie.Request, cookies: Cookie.Request*) =
68+
updateHeaders(_.addHeader(Header.Cookie(NonEmptyChunk(cookie, cookies: _*))))
69+
6470
/**
6571
* Add trailing slash to the path.
6672
*/

zio-http/shared/src/main/scala/zio/http/Response.scala

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ final case class Response(
4141
def addCookie(cookie: Cookie.Response): Response =
4242
self.copy(headers = self.headers ++ Headers(Header.SetCookie(cookie)))
4343

44+
def addCookies(cookie: Cookie.Response, cookies: Cookie.Response*) =
45+
updateHeaders(_.addHeaders(Headers.fromIterable((cookie +: cookies).map(Header.SetCookie(_)))))
46+
4447
/**
4548
* Adds flash values to the cookie-based flash-scope.
4649
*/

0 commit comments

Comments
 (0)