Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes #1177. Adds 'allAround' to LiftRules for putting loans around …

…the entire HTTP request
  • Loading branch information...
commit 67d29753bcc1e05283627eb070bddef7a9d498bd 1 parent dff0b6a
@dpp dpp authored
View
29 web/webkit/src/main/scala/net/liftweb/http/LiftRules.scala
@@ -956,9 +956,32 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
/**
* Holds user's DispatchPF functions that will be executed in a stateless context. This means that
- * S object is not availble yet.
+ * no session will be created and no JSESSIONID cookie will be presented to the user (unless
+ * the user has presented a JSESSIONID cookie).
*/
- val statelessDispatchTable = RulesSeq[DispatchPF]
+ @scala.deprecated("Use statelessDispatch")
+ def statelessDispatchTable = statelessDispatch
+
+ /**
+ * Holds user's DispatchPF functions that will be executed in a stateless context. This means that
+ * no session will be created and no JSESSIONID cookie will be presented to the user (unless
+ * the user has presented a JSESSIONID cookie).
+ *
+ * This is the way to do stateless REST in Lift
+ */
+ val statelessDispatch = RulesSeq[DispatchPF]
+
+ /**
+ * Add functionality around all of the HTTP request/response cycle.
+ * This is an optimal place to get a database connection. Note that whatever
+ * is loaned at the begining of the request will not be returned until the end
+ * of the request. It's super-important to (1) not do anything related
+ * to state or touch the request objects or anything else at the begining or
+ * end of the loan wrapper phase; (2) make sure that your code does not throw
+ * exceptions as exceptions can cause major problems.
+ */
+ val allAround = RulesSeq[LoanWrapper]
+
private[http] def dispatchTable(req: HTTPRequest): List[DispatchPF] = {
req match {
@@ -1772,7 +1795,7 @@ class RulesSeq[T] {
})(f)
}
- def toList = cur.value match {
+ def toList: List[T] = cur.value match {
case null => rules
case xs => xs
}
View
2  web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
@@ -257,7 +257,7 @@ class LiftServlet extends Loggable {
// if the request is matched is defined in the stateless table, dispatch
if (S.statelessInit(req) {
tmpStatelessHolder = NamedPF.applyBox(req,
- LiftRules.statelessDispatchTable.toList).map(_.apply() match {
+ LiftRules.statelessDispatch.toList).map(_.apply() match {
case Full(a) => Full(LiftRules.convertResponse((a, Nil, S.responseCookies, req)))
case r => r
});
View
2  web/webkit/src/main/scala/net/liftweb/http/provider/HTTPProvider.scala
@@ -99,7 +99,7 @@ trait HTTPProvider {
private def preBoot() {
// do this stateless
- LiftRules.statelessDispatchTable.prepend(NamedPF("Classpath service") {
+ LiftRules.statelessDispatch.prepend(NamedPF("Classpath service") {
case r@Req(mainPath :: subPath, suffx, _) if (mainPath == LiftRules.resourceServerPath) =>
ResourceServer.findResourceInClasspath(r, r.path.wholePath.drop(1))
})
View
19 web/webkit/src/main/scala/net/liftweb/http/provider/servlet/ServletFilterProvider.scala
@@ -50,6 +50,20 @@ trait ServletFilterProvider extends Filter with HTTPProvider {
def context: HTTPContext = ctx
/**
+ * Wrap the loans around the incoming request
+ */
+ private def handleLoanWrappers[T](f: => T): T = {
+ val wrappers = LiftRules.allAround.toList
+
+ def handleLoan(lst: List[LoanWrapper]): T = lst match {
+ case Nil => f
+ case x :: xs => x(handleLoan(xs))
+ }
+
+ handleLoan(wrappers)
+ }
+
+ /**
* Executes the Lift filter component.
*/
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain) = {
@@ -59,14 +73,15 @@ trait ServletFilterProvider extends Filter with HTTPProvider {
try {
TransientRequestVarHandler(Empty,
RequestVarHandler(Empty,
+
(req, res) match {
case (httpReq: HttpServletRequest, httpRes: HttpServletResponse) =>
val httpRequest = new HTTPRequestServlet(httpReq, this)
val httpResponse = new HTTPResponseServlet(httpRes)
- service(httpRequest, httpResponse) {
+ handleLoanWrappers(service(httpRequest, httpResponse) {
chain.doFilter(req, res)
- }
+ })
case _ => chain.doFilter(req, res)
}))
} finally {LiftRules.reqCnt.decrementAndGet()}
Please sign in to comment.
Something went wrong with that request. Please try again.