how to get the tail of ParsePath in RewriteResponse?

30 views
Skip to first unread message

wm

unread,
Nov 7, 2015, 1:03:27 PM11/7/15
to Lift
e.g.

      case RewriteRequest(
        ParsePath("foo" :: bar :: _, _, _, _), _, _) =>
        RewriteResponse("foo" :: Nil, Map("bar" -> _tail_))


I want _tail_ to be all the remaining parts except the first one (foo).

I tried to pattern match with just "foo" :: bar, it doesn't compile.

I just wonder how I can write this code?

Thanks.


wm

unread,
Nov 7, 2015, 1:13:08 PM11/7/15
to Lift
"/foo/bar/baz/qux/may/be/more"

I want get the tail = "bar/baz/qux/may/be/more"

Matt Farmer

unread,
Nov 7, 2015, 2:12:31 PM11/7/15
to Lift
You mention that this doesn’t compile when you just try to do “foo” :: bar. It’d probably be helpful for us for you to include that compiler error so we can have a look.

Better yet, if you could set up a sample project for us to play with, it’ll greatly increase the rate at which we can help you. :)


Matt Farmer | Blog | Twitter
GPG: CD57 2E26 F60C 0A61 E6D8  FC72 4493 8917 D667 4D07

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brett Grace

unread,
Nov 7, 2015, 4:54:22 PM11/7/15
to Lift
When I try this (what I think you probably tried)

case RewriteRequest(ParsePath("foo" :: bar , _, _, _), _, _) => RewriteResponse("foo" :: Nil, Map("bar" -> bar))        

I get the following error:

[error] /Users/bgrace/development/lift/SunsetFlora/src/main/scala/bootstrap/liftweb/Boot.scala:132: overloaded method value apply with alternatives:
[error]   (path: net.liftweb.http.ParsePath,params: Map[String,String])net.liftweb.http.RewriteResponse <and>
[error]   (path: List[String],suffix: String)net.liftweb.http.RewriteResponse <and>
[error]   (path: List[String],stopRewriting: Boolean)net.liftweb.http.RewriteResponse <and>
[error]   (path: List[String],params: Map[String,String])net.liftweb.http.RewriteResponse
[error]  cannot be applied to (List[String], scala.collection.immutable.Map[String,List[String]])
[error]       case RewriteRequest(ParsePath("foo" :: bar , _, _, _), _, _) => RewriteResponse("foo" :: Nil, Map("bar" -> bar))

I bolded the important bit. You can't pass in a Map[String, List[String]], which is what bar is at this point. If it's not clear, what you are capturing with the pattern match is the tail, but it's still in List[String] form. The RewriteResponse expects the Map to be a map of String -> String, not String -> List[String].

Perhaps you are intending something along these lines:

case RewriteRequest(ParsePath("foo" :: bar, _, _, _), _, _) => RewriteResponse("foo" :: Nil, Map("bar" -> bar.mkString("/")))

It wasn't clear whether you wanted to capture the wildcard in /foo/* or /foo/bar/* ... this does the former. If you wanted to try the latter, it would be:

case RewriteRequest(ParsePath("foo" :: "bar" :: baz, _, _, _), _, _) => RewriteResponse("foo" :: Nil, Map("bar" -> baz.mkString("/")))

Caveat: I only verified that this compiled, I didn't set up a test case to verify that it works as expected. But, you know, if it compiles it's probably correct.


On Saturday, November 7, 2015 at 10:03:27 AM UTC-8, wm wrote:

Antonio Salazar Cardozo

unread,
Nov 8, 2015, 10:50:28 PM11/8/15
to Lift
Also worth noting, it's strongly recommended that you not use RewriteRequest
unless you really know that that's what you want to do. It's used internally for things
but there are better/friendlier external interfaces in the form of dispatch/statelessDispatch
and the SiteMap.

If you're trying to do simple URI rewriting, I'd suggest you actually use nginx or
some other component that's designed to do that to take care of it—though obviously
that's not required and the rewrite stuff is part of the public API.
Thanks,
Antonio

DoomPirate

unread,
Nov 8, 2015, 11:29:17 PM11/8/15
to Lift
By the way, for OP. I have a thread on this forum related to URL rewriting. Lookup "Multiple websites on on server possible with lift?"
Reply all
Reply to author
Forward
0 new messages