Skip to content

Instantly share code, notes, and snippets.

@Shadowfiend
Created April 13, 2010 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shadowfiend/365111 to your computer and use it in GitHub Desktop.
Save Shadowfiend/365111 to your computer and use it in GitHub Desktop.
private object noCometResponseSent extends SessionVar[Boolean](false)
LiftRules.redirectAjaxOnSessionLoss = false
LiftRules.noCometSessionPage = "/home"
// Returns true if we should send an empty response for a comet request,
// false otherwise. This is used to ensure we don't send multiple
// window.location redirects in the event of a server restart in response
// to comet requests. Sending multiple ones can send Firefox into an
// infinite request loop that quickly consumes JVM resources and slows
// down the browser itself.
//
// It should only return true if this is the first time in this session
// that we see a comet request and meet the criteria for Lift sending
// back a window.location redirect to LiftRules.noCometSessionPage. Code
// for determining whether the actor list is empty was borrowed directly
// from LiftServlet.java.
def sendEmptyResponseForCometRequest(req:Req) = {
req.path.wholePath match {
case prefix :: tail if prefix == LiftRules.cometPath && (tail.length != 2 || tail(1) != LiftRules.cometScriptName()) =>
val actors: List[(LiftCometActor, Long)] =
req.params.toList.flatMap {
case (name, when) =>
S.session.open_!.getAsyncComponent(name).toList.map(c => (c, toLong(when)))
}
if (actors.isEmpty) {
if (noCometResponseSent.is)
true // clear the response, we don't want to send a redirect again
else {
noCometResponseSent(true)
false // send the response this time
}
}
else
false
case _ => false // don't clear the response, not a comet request
}
}
LiftRules.dispatch.append(NamedPF("CometRedirectStopper") {
case req if sendEmptyResponseForCometRequest(req) => () => Empty
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment