@@ -119,13 +119,6 @@ private[session] trait OneOffTapirSession[T] {
119119 case CookieOrHeaderST => oneOffCookieOrHeaderSession(required)
120120 }
121121
122- private [this ] def oneOffCookieSessionLogic (
123- cookie : Option [String ],
124- required : Option [Boolean ]
125- ): Either [Unit , (Option [CookieValueWithMeta ], SessionResult [T ])] = {
126- oneOffCookieOrHeaderSessionLogic(cookie, None , required).map(e => (e._1._1, e._2))
127- }
128-
129122 def oneOffCookieSession (
130123 required : Option [Boolean ] = None
131124 ): PartialServerEndpointWithSecurityOutput [Seq [Option [String ]], SessionResult [
@@ -140,23 +133,19 @@ private[session] trait OneOffTapirSession[T] {
140133 )
141134 .errorOut(statusCode(StatusCode .Unauthorized ))
142135 .serverSecurityLogicWithOutput { inputs =>
143- Future .successful(oneOffCookieSessionLogic(inputs.head, required) match {
144- case Left (l) => Left (l)
145- case Right (r) => Right (Seq (r._1.map(_.value)), r._2)
146- })
136+ Future .successful(
137+ oneOffCookieOrHeaderSessionLogic(inputs.head, None , required)
138+ .map(e => (e._1._1, e._2)) match {
139+ case Left (l) => Left (l)
140+ case Right (r) => Right ((Seq (r._1), r._2))
141+ }
142+ )
147143 }
148144 }
149145
150146 def extractOneOffSession (maybeValue : Option [String ]): Option [T ] =
151147 maybeValue.flatMap(manager.clientSessionManager.decode(_).toOption)
152148
153- private [this ] def oneOffHeaderSessionLogic (
154- header : Option [String ],
155- required : Option [Boolean ]
156- ): Either [Unit , (Option [String ], SessionResult [T ])] = {
157- oneOffCookieOrHeaderSessionLogic(None , header, required).map(e => (e._1._2, e._2))
158- }
159-
160149 def oneOffHeaderSession (
161150 required : Option [Boolean ] = None
162151 ): PartialServerEndpointWithSecurityOutput [Seq [Option [String ]], SessionResult [
@@ -171,49 +160,52 @@ private[session] trait OneOffTapirSession[T] {
171160 .mapOut(Seq (_))(_.head)
172161 .errorOut(statusCode(StatusCode .Unauthorized ))
173162 .serverSecurityLogicWithOutput { inputs =>
174- Future .successful(oneOffHeaderSessionLogic(inputs.head, required) match {
175- case Left (l) => Left (l)
176- case Right (r) => Right (Seq (r._1), r._2)
177- })
163+ Future .successful(
164+ oneOffCookieOrHeaderSessionLogic(None , inputs.head, required)
165+ .map(e => (e._1._2, e._2)) match {
166+ case Left (l) => Left (l)
167+ case Right (r) => Right ((Seq (r._1), r._2))
168+ }
169+ )
178170 }
179171
180172 def oneOffCookieOrHeaderSessionLogic (
181173 maybeCookie : Option [String ],
182174 maybeHeader : Option [String ],
183175 required : Option [Boolean ]
184- ): Either [Unit , ((Option [CookieValueWithMeta ], Option [String ]), SessionResult [T ])] = {
185- maybeCookie match {
186- case Some (cookie) =>
187- val decoded = manager.clientSessionManager.decode(cookie)
176+ ): Either [Unit , ((Option [String ], Option [String ]), SessionResult [T ])] = {
177+ // read session from the cookie and/or header
178+ val oneOff = maybeCookie.fold(maybeHeader)(Some (_))
179+ oneOff match {
180+ case Some (value) =>
181+ val decoded = manager.clientSessionManager.decode(value)
188182 decoded match {
189- case SessionResult .Expired | SessionResult .Corrupt (_) =>
190- Right ((None , maybeHeader), decoded)
183+ case s : SessionResult .DecodedLegacy [T ] =>
184+ Right (
185+ (
186+ (
187+ Some (manager.clientSessionManager.encode(s.session)),
188+ maybeHeader.map(_ => value)
189+ ),
190+ s
191+ )
192+ )
191193 case s =>
192194 Right (
193195 (
194- Some (manager.clientSessionManager.createCookieWithValue(cookie).valueWithMeta),
195- maybeHeader
196- ),
197- s
196+ (
197+ None ,
198+ None
199+ ),
200+ s
201+ )
198202 )
199203 }
200204 case _ =>
201- maybeHeader match {
202- case Some (header) =>
203- val decoded = manager.clientSessionManager.decode(header)
204- decoded match {
205- case SessionResult .Expired | SessionResult .Corrupt (_) =>
206- if (required.getOrElse(false ))
207- Left (())
208- else
209- Right ((None , None ), decoded)
210- case s => Right ((None , Some (header)), s)
211- }
212- case _ =>
213- if (required.getOrElse(false ))
214- Left (())
215- else
216- Right ((None , None ), SessionResult .NoSession )
205+ if (required.getOrElse(false )) {
206+ Left (())
207+ } else {
208+ Right (((None , None ), SessionResult .NoSession ))
217209 }
218210 }
219211 }
@@ -239,7 +231,7 @@ private[session] trait OneOffTapirSession[T] {
239231 .serverSecurityLogicWithOutput { inputs =>
240232 Future .successful(
241233 oneOffCookieOrHeaderSessionLogic(inputs.head, inputs.last, required)
242- .map(result => (Seq (result._1._1.map(_.value) , result._1._2), result._2))
234+ .map(result => (Seq (result._1._1, result._1._2), result._2))
243235 )
244236 }
245237
@@ -254,33 +246,37 @@ private[session] trait OneOffTapirSession[T] {
254246 maybeHeader match {
255247 case Some (_) =>
256248 Right (
257- Seq (
258- Some (" deleted" ),
259- Some (" " )
260- ),
261- principal
249+ (
250+ Seq (
251+ Some (" deleted" ),
252+ Some (" " )
253+ ),
254+ principal
255+ )
262256 )
263257 case _ =>
264258 Right (
265- Seq (
266- Some (" deleted" ),
267- None
268- ),
269- principal
259+ (
260+ Seq (
261+ Some (" deleted" ),
262+ None
263+ ),
264+ principal
265+ )
270266 )
271267 }
272268 case _ =>
273269 maybeHeader match {
274- case Some (_) => Right (Seq (None , Some (" " )), principal)
275- case _ => Right (Seq (None , None ), principal)
270+ case Some (_) => Right (( Seq (None , Some (" " )), principal) )
271+ case _ => Right (( Seq (None , None ), principal) )
276272 }
277273 }
278274 }
279275
280276 def invalidateOneOffSession [
281277 SECURITY_INPUT ,
282278 PRINCIPAL
283- ](
279+ ](st : GetSessionTransport )(
284280 body : => PartialServerEndpointWithSecurityOutput [
285281 SECURITY_INPUT ,
286282 PRINCIPAL ,
@@ -343,12 +339,12 @@ private[session] trait OneOffTapirSession[T] {
343339 val session = r._2
344340 st match {
345341 case CookieST | HeaderST =>
346- setOneOffSessionLogic(session.toOption, inputs.head )
342+ setOneOffSessionLogic(session.toOption, None )
347343 .map(result => (Seq (result), session))
348344 case CookieOrHeaderST =>
349345 val maybeCookie = inputs.head
350346 val maybeHeader = inputs.last
351- setOneOffSessionLogic(session.toOption, inputs.head )
347+ setOneOffSessionLogic(session.toOption, None )
352348 .map(result =>
353349 (
354350 Seq (maybeCookie.flatMap(_ => result), maybeHeader.flatMap(_ => result)),
0 commit comments