What's the best way to get the current request URL

已查看 421 次
跳至第一个未读帖子

Ryan Donahue

未读,
2009年9月16日 09:35:012009/9/16
收件人 Lift
I want to capture the the current request URL, so I can redirect back
to it at a later point. What's the best way to get at the URL? The
answer is probably obvious, but I can't seem to find it.

Thanks,

Ryan

harryh

未读,
2009年9月16日 11:21:442009/9/16
收件人 Lift
S.uri

Ryan Donahue

未读,
2009年9月16日 11:33:092009/9/16
收件人 lif...@googlegroups.com
Does that include the query string?

David Pollak

未读,
2009年9月18日 13:33:122009/9/18
收件人 lif...@googlegroups.com
On Wed, Sep 16, 2009 at 8:33 AM, Ryan Donahue <dona...@gmail.com> wrote:
Does that include the query string?

No.
 



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

wm

未读,
2015年11月7日 12:42:492015/11/7
收件人 Lift、feeder.of...@gmail.com
Ok, we know it's "No".

Then the next natural question is:

how to get the current request URL _with_ the whole query string?

wm

未读,
2015年11月7日 12:45:502015/11/7
收件人 Lift、feeder.of...@gmail.com
uriAndQueryString: Box[String]?

why its return type is Box[String] instead of just String?

Matt Farmer

未读,
2015年11月7日 14:10:512015/11/7
收件人 Lift
I believe it’s a Box[String] because you could access that from outside the context of a request. So, for example, if you try to read that value from an actor you’d see Empty.

This is a bit confusing given that uri won’t return Empty in the same case. That’s probably an inconsistency that should be resolved at some point soon.


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

未读,
2015年11月7日 14:16:342015/11/7
收件人 Lift
Well, I suppose because there may not be one—you can access the S object outside of an HTTP request/response cycle. One could as well ask why uri doesn't
 return a Box/Option. If you look at the code it handles the Empty/None case with a default of "/" in just those cases. I suspect this is very old code in Lift so there may not be a consistent rationalization.

Oh, if you look at the comments for this code, it suggests a way to get the raw URI + query string (I believe Lift omits the application context):

* If you want the full URI, including the context path, you should retrieve it
* from the underlying HTTPRequest. You could do something like:
*
* <pre name="code" class="scala" >
* val fullURI = S.request.map(_.request.getRequestURI) openOr ("Undefined")
* </pre>

wm

未读,
2015年12月29日 19:50:132015/12/29
收件人 Lift
[error]

value getRequestURI is not a member of net.liftweb.http.provider.HTTPRequest

Antonio Salazar Cardozo

未读,
2015年12月30日 11:04:452015/12/30
收件人 Lift
Try just `uri` instead of `getRequestURI`. If that works, I'll update the docs.
Thanks,
Antonio
回复全部
回复作者
转发
0 个新帖子