Chapter 6. Request Pipeline
When a request reaches Lift, there are a number of points where you can jump in and control what Lift does, sending back a different kind of response or controlling access. This chapter looks at the pipeline through examples of different kinds of
LiftResponses and configurations.
You can get a great overview of the pipeline, including diagrams, from the Lift pipeline wiki page.
See https://github.com/LiftCookbook/cookbook_pipeline for the source code that accompanies this chapter.
Debugging a Request
Problem
You want to debug a request and see what’s arriving to your Lift application.
Solution
Add an onBeginServicing function in Boot.scala to log the request.
For example:
LiftRules.onBeginServicing.append{caser=>println("Received: "+r)}
Discussion
The onBeginServicing call is called quite early in the Lift pipeline, before
S is set up, and before Lift has the chance to 404 your request. The function signature it expects is Req => Unit.
We’re just logging, but the functions could be used for other purposes.
If you want to select only certain paths, you can. For example, to track all requests starting /paypal:
LiftRules.onBeginServicing.append{caser@Req("paypal"::_),_,_)=>println(r)}
This pattern will match any request starting /paypal, and we’re ignoring the suffix on the request, if any, and the type of request (e.g., GET, POST, or so on).
There’s also LiftRules.early, which is called before onBeginServicing. It expects an HTTPRequest => Unit function, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access