@@ -32,79 +32,107 @@ private[session] trait OneOffTapirSession[T] {
3232 header[Option [String ]](manager.config.sessionHeaderConfig.sendToClientHeaderName)
3333 }
3434
35- def setOneOffSession [INPUT ](st : SetSessionTransport )(
36- endpoint : => Endpoint [INPUT , Unit , Unit , Unit , Any ]
37- )(implicit
38- f : INPUT => Option [T ]
39- ): PartialServerEndpointWithSecurityOutput [(INPUT , Seq [Option [String ]]), Option [
35+ def setOneOffSession [SECURITY_INPUT , SECURITY_OUTPUT ](st : SetSessionTransport )(
36+ body : => PartialServerEndpointWithSecurityOutput [
37+ SECURITY_INPUT ,
38+ Option [T ],
39+ Unit ,
40+ Unit ,
41+ SECURITY_OUTPUT ,
42+ Unit ,
43+ Any ,
44+ Future
45+ ]
46+ ): PartialServerEndpointWithSecurityOutput [(SECURITY_INPUT , Seq [Option [String ]]), Option [
4047 T
41- ], Unit , Unit , Seq [Option [String ]], Unit , Any , Future ] =
48+ ], Unit , Unit , ( SECURITY_OUTPUT , Seq [Option [String ]]) , Unit , Any , Future ] =
4249 st match {
43- case CookieST => setOneOffCookieSession(endpoint )
44- case HeaderST => setOneOffHeaderSession(endpoint )
50+ case CookieST => setOneOffCookieSession(body )
51+ case HeaderST => setOneOffHeaderSession(body )
4552 }
4653
47- private [this ] def setOneOffSessionLogic [ INPUT ] (
48- input : INPUT ,
49- existing : Option [String ]
50- )( implicit f : INPUT => Option [ T ]) : Either [Unit , Option [String ]] =
54+ private [this ] def setOneOffSessionLogic (
55+ option : Option [ T ] ,
56+ existing : Option [String ]
57+ ): Either [Unit , Option [String ]] =
5158 existing match {
5259 case Some (value) =>
5360 Right (
5461 Some (value)
5562 )
5663 case _ =>
57- implicitly[ Option [ T ]](input) match {
64+ option match {
5865 case Some (v) => Right (Some (manager.clientSessionManager.encode(v)))
5966 case _ => Left (())
6067 }
6168 }
6269
63- def setOneOffCookieSession [INPUT ](
64- endpoint : => Endpoint [INPUT , Unit , Unit , Unit , Any ]
65- )(implicit
66- f : INPUT => Option [T ]
67- ): PartialServerEndpointWithSecurityOutput [(INPUT , Seq [Option [String ]]), Option [
70+ def setOneOffCookieSession [SECURITY_INPUT , SECURITY_OUTPUT ](
71+ body : => PartialServerEndpointWithSecurityOutput [
72+ SECURITY_INPUT ,
73+ Option [T ],
74+ Unit ,
75+ Unit ,
76+ SECURITY_OUTPUT ,
77+ Unit ,
78+ Any ,
79+ Future
80+ ]
81+ ): PartialServerEndpointWithSecurityOutput [(SECURITY_INPUT , Seq [Option [String ]]), Option [
6882 T
69- ], Unit , Unit , Seq [Option [String ]], Unit , Any , Future ] =
70- endpoint
83+ ], Unit , Unit , (SECURITY_OUTPUT , Seq [Option [String ]]), Unit , Any , Future ] =
84+ body
85+ .endpoint
7186 .securityIn(getSessionFromClientAsCookie.map(Seq (_))(_.head))
72- .out(sendSessionToClientAsCookie)
73- .mapOut(o => Seq (o.map(_.value)))(
74- _.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta)
87+ .out(body.securityOutput)
88+ .out(
89+ sendSessionToClientAsCookie.map(o => Seq (o.map(_.value)))(
90+ _.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta)
91+ )
7592 )
7693 .serverSecurityLogicWithOutput { inputs =>
77- Future .successful(
78- setOneOffSessionLogic(inputs._1, inputs._2.head).map(result =>
79- (
80- Seq (result),
81- inputs._1
94+ body.securityLogic(new FutureMonad ())(inputs._1) map {
95+ case Left (l) => Left (l)
96+ case Right (r) =>
97+ setOneOffSessionLogic(r._2, inputs._2.head).map(result =>
98+ (
99+ (r._1, Seq (result)),
100+ r._2
101+ )
82102 )
83- )
84- )
103+ }
85104 }
86105
87- def setOneOffHeaderSession [INPUT ](
88- endpoint : Endpoint [INPUT , Unit , Unit , Unit , Any ]
89- )(implicit
90- f : INPUT => Option [T ]
91- ): PartialServerEndpointWithSecurityOutput [(INPUT , Seq [Option [String ]]), Option [
106+ def setOneOffHeaderSession [SECURITY_INPUT , SECURITY_OUTPUT ](
107+ body : => PartialServerEndpointWithSecurityOutput [
108+ SECURITY_INPUT ,
109+ Option [T ],
110+ Unit ,
111+ Unit ,
112+ SECURITY_OUTPUT ,
113+ Unit ,
114+ Any ,
115+ Future
116+ ]
117+ ): PartialServerEndpointWithSecurityOutput [(SECURITY_INPUT , Seq [Option [String ]]), Option [
92118 T
93- ], Unit , Unit , Seq [Option [String ]], Unit , Any , Future ] =
94- endpoint
119+ ], Unit , Unit , (SECURITY_OUTPUT , Seq [Option [String ]]), Unit , Any , Future ] =
120+ body
121+ .endpoint
95122 .securityIn(getSessionFromClientAsHeader.map(Seq (_))(_.head))
96- .out(sendSessionToClientAsHeader )
97- .mapOut( Seq (_))(_.head)
123+ .out(body.securityOutput )
124+ .out(sendSessionToClientAsHeader.map( Seq (_))(_.head) )
98125 .serverSecurityLogicWithOutput { inputs =>
99- Future .successful(
100- setOneOffSessionLogic(inputs._1, inputs._2.head)
101- .map(result =>
126+ body.securityLogic(new FutureMonad ())(inputs._1) map {
127+ case Left (l) => Left (l)
128+ case Right (r) =>
129+ setOneOffSessionLogic(r._2, inputs._2.head).map(result =>
102130 (
103- Seq (result),
104- inputs._1
131+ (r._1, Seq (result) ),
132+ r._2
105133 )
106134 )
107- )
135+ }
108136 }
109137
110138 def oneOffSession (
@@ -127,9 +155,10 @@ private[session] trait OneOffTapirSession[T] {
127155 endpoint
128156 .securityIn(getSessionFromClientAsCookie)
129157 .mapSecurityIn(Seq (_))(_.head)
130- .out(sendSessionToClientAsCookie)
131- .mapOut(o => Seq (o.map(_.value)))(oo =>
132- oo.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta)
158+ .out(
159+ sendSessionToClientAsCookie.map(o => Seq (o.map(_.value)))(oo =>
160+ oo.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta)
161+ )
133162 )
134163 .errorOut(statusCode(StatusCode .Unauthorized ))
135164 .serverSecurityLogicWithOutput { inputs =>
@@ -156,8 +185,7 @@ private[session] trait OneOffTapirSession[T] {
156185 getSessionFromClientAsHeader
157186 )
158187 .mapSecurityIn(Seq (_))(_.head)
159- .out(sendSessionToClientAsHeader)
160- .mapOut(Seq (_))(_.head)
188+ .out(sendSessionToClientAsHeader.map(Seq (_))(_.head))
161189 .errorOut(statusCode(StatusCode .Unauthorized ))
162190 .serverSecurityLogicWithOutput { inputs =>
163191 Future .successful(
@@ -219,13 +247,15 @@ private[session] trait OneOffTapirSession[T] {
219247 .securityIn(getSessionFromClientAsCookie)
220248 .securityIn(getSessionFromClientAsHeader)
221249 .mapSecurityIn(inputs => Seq (inputs._1, inputs._2))(oo => (oo.head, oo.last))
222- .out(sendSessionToClientAsCookie)
223- .out(sendSessionToClientAsHeader)
224- .mapOut(outputs => Seq (outputs._1.map(_.value), outputs._2))(oo =>
225- (
226- oo.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta),
227- oo.last
228- )
250+ .out(
251+ sendSessionToClientAsCookie
252+ .and(sendSessionToClientAsHeader)
253+ .map(outputs => Seq (outputs._1.map(_.value), outputs._2))(oo =>
254+ (
255+ oo.head.map(manager.clientSessionManager.createCookieWithValue(_).valueWithMeta),
256+ oo.last
257+ )
258+ )
229259 )
230260 .errorOut(statusCode(StatusCode .Unauthorized ))
231261 .serverSecurityLogicWithOutput { inputs =>
@@ -303,18 +333,20 @@ private[session] trait OneOffTapirSession[T] {
303333 .mapSecurityIn(inputs => (inputs._1, Seq (inputs._2, inputs._3)))(oo =>
304334 (oo._1, oo._2.head, oo._2.last)
305335 )
306- .out(sendSessionToClientAsCookie)
307- .out(sendSessionToClientAsHeader)
308- .mapOut(outputs => Seq (outputs._1.map(_.value), outputs._2))(oo =>
309- (
310- oo.head.map(
311- manager.clientSessionManager
312- .createCookieWithValue(_)
313- .withExpires(DateTime .MinValue )
314- .valueWithMeta
315- ),
316- oo.last
317- )
336+ .out(
337+ sendSessionToClientAsCookie
338+ .and(sendSessionToClientAsHeader)
339+ .map(outputs => Seq (outputs._1.map(_.value), outputs._2))(oo =>
340+ (
341+ oo.head.map(
342+ manager.clientSessionManager
343+ .createCookieWithValue(_)
344+ .withExpires(DateTime .MinValue )
345+ .valueWithMeta
346+ ),
347+ oo.last
348+ )
349+ )
318350 )
319351 .serverSecurityLogicWithOutput { inputs =>
320352 body.securityLogic(new FutureMonad ())(inputs._1).map {
0 commit comments