REST Requst suffix matching

117 views
Skip to first unread message

cristian.vrabie

unread,
Dec 14, 2011, 8:44:35 AM12/14/11
to Lift
Anyone know there's a suffix matching problem in Lift 2.4-M5?
Or am I doing something wrong here?

For this URL: http://localhost:8080/reports/scores/overall.csv

The following rule doesn't match:
case Req("reports" :: "scores" :: "overall" :: Nil, "csv", GetRequest)
=>

However, this one does:
case Req("reports" :: "scores" :: "overall.csv" :: Nil, _, GetRequest)
=>

Diego Medina

unread,
Dec 14, 2011, 11:49:23 AM12/14/11
to lif...@googlegroups.com
how about this one:

case Req("reports" :: "scores" :: Nil, "csv", GetRequest) =>
or
case Req("reports" :: "scores" :: _ :: Nil, "csv", GetRequest) =>

Not that I know, but I learn a lot by trial and error :)

Regards,

Diego

> --
> 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

--
Diego Medina
Web Developer
di...@fmpwizard.com
http://www.fmpwizard.com

cristian.vrabie

unread,
Dec 14, 2011, 12:25:21 PM12/14/11
to Lift
I tried this one with the same result:

case Req("reports" :: "scores" :: "overall" :: _ , "csv", GetRequest)

From what I know, this should match no matter what you suffix that URL
with.

Btw, sorry for my English in my earlier post. Now that I read it I
realize that it sound like a baboon :) That happens when you form your
phrases from several pastes and don't check the result.

Sergey Trofimov

unread,
Dec 14, 2011, 11:28:35 PM12/14/11
to lif...@googlegroups.com
This line in boot should help:

LiftRules.explicitlyParsedSuffixes += "csv"



--
Sergey Trofimov

Sören Kress

unread,
Dec 15, 2011, 8:58:20 AM12/15/11
to lif...@googlegroups.com
Good to know.

The HttpHelpers trait contains a really big set of known suffixes (see below) and I know, that this list will never be complete, but what about adding at least the following suffixes:

- csv
- docx, pptx, xlsx
- sxw, sxc, sxd, sxi, sxm, sxg (Open Office)

Best regards
Soeren

    val knownSuffixes: Set[String] = Set("json","rss","atom","do","3dm",
                                         "3dmf","a","aab","aam","aas","abc","acgi","afl","ai","aif","aifc","aiff",
                                         "aim","aip","ani","aos","aps","arc","arj","art","asf","asm","asp","asx","au","avi","avs",
                                         "bcpio","bin","bm","bmp","boo","book","boz","bsh","bz","bz2","c","c++","cat","cc","ccad",
                                         "cco","cdf","cer","cha","chat","class","com","conf","cpio","cpp","cpt","crl","crt","csh",
                                         "css","cxx","dcr","deepv","def","der","dif","dir","dl","doc","dot","dp","drw","dump","dv",
                                         "dvi","dwf","dwg","dxf","dxr","el","elc","env","eps","es","etx","evy","exe","f","f77",
                                         "f90","fdf","fif","fli","flo","flx","fmf","for","fpx","frl","funk","g","g3","gif","gl","gsd",
                                         "gsm","gsp","gss","gtar","gz","gzip","h","hdf","help","hgl","hh","hlb","hlp","hpg","hpgl",
                                         "hqx","hta","htc","htm","html","htmls","htt","htx","ice","ico","idc","ief","iefs","iges","igs",
                                         "ima","imap","inf","ins","ip","isu","it","iv","ivr","ivy","jam","jav","java","jcm","jfif",
                                         "jfif-tbnl","jpe","jpeg","jpg","jps","js","jut","kar","ksh","la","lam","latex","lha","lhx",
                                         "list","lma","log","lsp","lst","lsx","ltx","lzh","lzx","m","m1v","m2a","m2v","m3u","man","map",
                                         "mar","mbd","mc$","mcd","mcf","mcp","me","mht","mhtml","mid","midi","mif","mime","mjf","mjpg",
                                         "mm","mme","mod","moov","mov","movie","mp2","mp3","mpa","mpc","mpe","mpeg","mpg","mpga","mpp",
                                         "mpt","mpv","mpx","mrc","ms","mv","my","mzz","nap","naplps","nc","ncm","nif","niff","nix",
                                         "nsc","nvd","o","oda","omc","omcd","omcr","p","p10","p12","p7a","p7c","p7m","p7r","p7s","part",
                                         "pas","pbm","pcl","pct","pcx","pdb","pdf","pfunk","pgm","pic","pict","pkg","pko","pl","plx","pm",
                                         "pm4","pm5","png","pnm","pot","pov","ppa","ppm","pps","ppt","ppz","pre","prt","ps","psd",
                                         "pvu","pwz","py","pyc","qcp","qd3","qd3d","qif","qt","qtc","qti","qtif","ra","ram","ras",
                                         "rast","rexx","rf","rgb","rm","rmi","rmm","rmp","rng","rnx","roff","rp","rpm","rt","rtf","rtx",
                                         "rv","s","s3m","saveme","sbk","scm","sdml","sdp","sdr","sea","set","sgm","sgml","sh","shar",
                                         "shtml","sid","sit","skd","skm","skp","skt","sl","smi","smil","snd","sol","spc","spl","spr",
                                         "sprite","src","ssi","ssm","sst","step","stl","stp","sv4cpio","sv4crc","svf","svr","swf","t",
                                         "talk","tar","tbk","tcl","tcsh","tex","texi","texinfo","text","tgz","tif","tiff","tr","tsi",
                                         "tsp","tsv","turbot","txt","uil","uni","unis","unv","uri","uris","ustar","uu","uue","vcd","vcs",
                                         "vda","vdo","vew","viv","vivo","vmd","vmf","voc","vos","vox","vqe","vqf","vql","vrml","vrt",
                                         "vsd","vst","vsw","w60","w61","w6w","wav","wb1","wbmp","web","wiz","wk1","wmf","wml","wmlc",
                                         "wmls","wmlsc","word","wp","wp5","wp6","wpd","wq1","wri","wrl","wrz","wsc","wsrc","wtk","x-png",
                                         "xbm","xdr","xgz","xif","xl","xla","xlb","xlc","xld","xlk","xll","xlm","xls","xlt","xlv","xlw",
                                         "xm","xml","xmz","xpix","xpm","xsr","xwd","xyz","z","zip","zoo","zsh")

David Pollak

unread,
Dec 15, 2011, 11:09:08 AM12/15/11
to lif...@googlegroups.com
You can add your own in Boot.scala via LiftRules.exolicitlyParsedSuffixes:

  /**
   * When a request is parsed into a Req object, certain suffixes are explicitly split from
   * the last part of the request URI.  If the suffix is contained in this list, it is explicitly split.
   * The default list is: "html", "htm", "jpg", "png", "gif", "xml", "rss", "json" ...
   */
  @volatile var explicitlyParsedSuffixes: Set[String] = knownSuffixes

--
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



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net

Sören Kress

unread,
Dec 15, 2011, 11:53:57 AM12/15/11
to lif...@googlegroups.com
Yes, I know. But only because Sergey mentioned it already. 

Obviously Cristian didn't knew it as well - otherwise he would not have posted this topic. "Lift in Action" which helped and still helps me a lot also does not mention this method (at least searching for 'explicitlyParsedSuffixes' yields no results).

I was quite surprised that there is such a method. All examples that I came across that used some kind of pattern matching involving a ParsePath either used "_" as suffix or something like "xml". And ParsePath's Scala doc also doesn't mention LiftRules.explicitlyParsedSuffixes. Without this great community it would have been (relatively) hard to find the solution to Cristian's problem.

And as I saw this really big set of known suffixes which contains a couple of suffixes that I do not know, I was just wondering why "csv" was not included or if it could be added. And perhaps a little hint in the ParsePath Scala doc could be really helpful.

Best regards
Soeren

P.S.: Didn't someone on this list mentioned the idea of adding a community wiki to the scala doc? That would be great such that non-committers could help out with some hints.

David Pollak

unread,
Dec 15, 2011, 1:17:32 PM12/15/11
to lif...@googlegroups.com
On Thu, Dec 15, 2011 at 8:53 AM, Sören Kress <soeren...@gmail.com> wrote:
Yes, I know. But only because Sergey mentioned it already. 

Obviously Cristian didn't knew it as well - otherwise he would not have posted this topic. "Lift in Action" which helped and still helps me a lot also does not mention this method (at least searching for 'explicitlyParsedSuffixes' yields no results).

So, why haven't you written a Wiki page about it to help others?
 

I was quite surprised that there is such a method. All examples that I came across that used some kind of pattern matching involving a ParsePath either used "_" as suffix or something like "xml". And ParsePath's Scala doc also doesn't mention LiftRules.explicitlyParsedSuffixes. Without this great community it would have been (relatively) hard to find the solution to Cristian's problem.

And that's why we have a great community to help others.  But the community stays great and upbeat when people add to the documentation (wiki) rather than complaining.
 

And as I saw this really big set of known suffixes which contains a couple of suffixes that I do not know, I was just wondering why "csv" was not included or if it could be added. And perhaps a little hint in the ParsePath Scala doc could be really helpful.


You can search this group for the discussion about parsing suffixes and you'll have all the information on the subject.

The current list is Pareto Optimal.  Any change will silently impact someone and given that the cost of making the list what you want it to be is a single line in Boot, in my opinion, the costs of change (silently breaking someone's code) outweighs the benefit of adding extra suffixes.
 

Best regards
Soeren

P.S.: Didn't someone on this list mentioned the idea of adding a community wiki to the scala doc? That would be great such that non-committers could help out with some hints.

--
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

Sören Kress

unread,
Dec 16, 2011, 2:17:32 AM12/16/11
to lif...@googlegroups.com


On Thursday, December 15, 2011 7:17:32 PM UTC+1, David Pollak wrote:


On Thu, Dec 15, 2011 at 8:53 AM, Sören Kress <soeren...@gmail.com> wrote:
Yes, I know. But only because Sergey mentioned it already. 

Obviously Cristian didn't knew it as well - otherwise he would not have posted this topic. "Lift in Action" which helped and still helps me a lot also does not mention this method (at least searching for 'explicitlyParsedSuffixes' yields no results).

So, why haven't you written a Wiki page about it to help others?
 

I was quite surprised that there is such a method. All examples that I came across that used some kind of pattern matching involving a ParsePath either used "_" as suffix or something like "xml". And ParsePath's Scala doc also doesn't mention LiftRules.explicitlyParsedSuffixes. Without this great community it would have been (relatively) hard to find the solution to Cristian's problem.

And that's why we have a great community to help others.  But the community stays great and upbeat when people add to the documentation (wiki) rather than complaining.
 
I would have written a wiki page if it would have made sense (to me). And I am not complaining - I am just pointing out that I think it would be useful to change something in an area where a developer (that did not yet memorize Lift's complete sourcecode) would try to find a hint: the API docs. At least that's where I was looking at when trying to find an answer to Cristian's question. I tried his code and did not find a solution for _his_ problem within a couple of minutes. What I noticed is that it was working with some suffixes but not all. But I did not have the time to dig into Lift's source code to solve other people's problems. That's why I stopped my effort and thanks to Sergey (and later you) the explanation to Cristian's question was given on this list. And after reading Sergey's answer I was just spending another couple of minutes to give some feedback.


Reply all
Reply to author
Forward
0 new messages