Question about headers and sessions

10 views
Skip to first unread message

Donald McLean

unread,
Apr 6, 2021, 11:17:00 AM4/6/21
to liftweb
I'm working on implementing my side of SSO, which is done by the proxy
adding data to the headers. So in the render method for the app's main
content block, I can get the Lift session information, but not the
actual request headers. I can add a handler with
LiftRules.onBeginServicing that can see the headers, but not the Lift
session information. So how do I get these two pieces to come
together?

Andreas Joseph Krogh

unread,
Apr 6, 2021, 11:29:14 AM4/6/21
to Donald McLean, liftweb
net.liftweb.http.Req, available from S.request (Box[Req])
 
So you can call:
S.request.flatMap(_.header("interestingHeaderName")).foreach{headerValue =>
   println(s"interestingHeaderName: $headerValue")
}
Is this what you're looking for?

--
Andreas Joseph Krogh

Donald McLean

unread,
Apr 6, 2021, 12:05:31 PM4/6/21
to liftweb
It would if that actually worked.

This code:

S.session match {
case Full(session) => logger.warn("[ChangeBlockImpl.render] session:
{}", session)
case Empty => logger.warn("[ChangeBlockImpl.render] no session.")
case f: Failure => logger.warn("[ChangeBlockImpl.render] failed to
get session: {}", f)
}
S.request match {
case Full(request) => logger.warn("[ChangeBlockImpl.render] request
headers: {}", request.headers)
case Empty => logger.error("[ChangeBlockImpl.render] no request.")
case f: Failure => logger.error("[ChangeBlockImpl.render] failure
getting request: {}", f)
}

Produces this output:

2021-04-06 16:02:21,317 WARN [pool-1-thread-3] e.s.l.c.ChangeBlockImpl
[ChangeBlock.scala:59] [ChangeBlockImpl.render] session:
net.liftweb.http.LiftSession@518e1cd3
2021-04-06 16:02:21,317 ERROR [pool-1-thread-3]
e.s.l.c.ChangeBlockImpl [ChangeBlock.scala:65]
[ChangeBlockImpl.render] no request.
--
Family photographs are a critical legacy for
ourselves and our descendants. Protect that
legacy with a digital backup and recovery plan.

Andreas Joseph Krogh

unread,
Apr 6, 2021, 1:01:37 PM4/6/21
to lif...@googlegroups.com
På tirsdag 06. april 2021 kl. 18:05:16, skrev Donald McLean <dmcl...@gmail.com>:
It would if that actually worked.

This code:

S.session match {
  case Full(session) => logger.warn("[ChangeBlockImpl.render] session:
{}", session)
  case Empty => logger.warn("[ChangeBlockImpl.render] no session.")
  case f: Failure => logger.warn("[ChangeBlockImpl.render] failed to
get session: {}", f)
}
S.request match {
  case Full(request) => logger.warn("[ChangeBlockImpl.render] request
headers: {}", request.headers)
  case Empty => logger.error("[ChangeBlockImpl.render] no request.")
  case f: Failure => logger.error("[ChangeBlockImpl.render] failure
getting request: {}", f)
}

Produces this output:

2021-04-06 16:02:21,317 WARN [pool-1-thread-3] e.s.l.c.ChangeBlockImpl
[ChangeBlock.scala:59] [ChangeBlockImpl.render] session:
net.liftweb.http.LiftSession@518e1cd3
2021-04-06 16:02:21,317 ERROR [pool-1-thread-3]
e.s.l.c.ChangeBlockImpl [ChangeBlock.scala:65]
[ChangeBlockImpl.render] no request.
 
Judging from the log-output it seems you are running this code in an "executer-service", and not in the context of a request, in an Actor maybe?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 

Donald McLean

unread,
Apr 6, 2021, 1:24:23 PM4/6/21
to liftweb
Thank you, Andreas, that is exactly correct. Moving the code to a non-comet actor block was the solution.
Reply all
Reply to author
Forward
0 new messages