Dear Smalltalkers (Pharonistas?),
while trying out teapot in Pharo4, I encountered the following: I have made a plain HTML form which sends data to a teapot URL. Here is what the browser is sending: http://localhost:1701/bac/?a=88&r=0.7&kg=77 To answer this request via teapot, I wrote the following: ... GET:'\/bac\/\?a=(\d*)&r=(\d*.\d*)&kg=(\d*)' asRegex -> [:req | BloodAlcoholCalculator a:(req at:1) r:(req at:2) kg:(req at:3) ]; ... But the answer in the Browser looks like: Not Found /bac/?r=0.7&a=88&kg=77 I tested the regular expression via 'matchesRegex' and it returned 'true'. The funny thing is, that teapot changes the order of the values in the answer (r and a are switched). If I leave out the '\?' and use the resulting URL manually, teapot delivers the expected behaviour. What could be the reason for this issue and where should I search to understand it (System Browser)? Thanks for the attention and kind regards Marcus -- View this message in context: http://forum.world.st/Teapot-and-Regex-tp4840892.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
Marcus,
I have no answers to your questions, but it seems like you expect the URL parameters in a specified order. I am nat sure this is a good idea at all. So independent on why the order of the parameters is changed and by whom: you shouldn't rely on it. Sure, this doesn't really help to understand or fix the problem at hand. But there should be no problem if you handled parameters by name rather than their order. Are you sure the order of parameters is changed by Teapot? Joachim -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
This post was updated on .
Hi Joachim,
thanks for your feedback. Concerning the order of the values I rely solely on the teapot error message. Besides I have no idea how I could make this GET request independant from the order the HTML form generated. Maybe with Javascript? But I assume this simple scenario should work in teapot and I just didn't understand it correctly... Kind regards Marcus |
In reply to this post by jtuchel
Hi Joachim,
thanks for your feedback. Concerning the order of the values I rely solely on the teapot error message. Besides I have no idea how I could make this GET request independant from the order the HTML form generated. Maybe with Javascript? But I assume this simple scenario should work in teapot and I just understand it correctly... Kind regards Marcus -- View this message in context: http://forum.world.st/Teapot-and-Regex-tp4840893p4840908.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
Marcus,
>Hi Joachim, > thanks for your feedback. Concerning the order of the values I rely solely > on the teapot error message. The way I understand your code snippet, you access the url parameters by using "at: 1". I have never used Teapot, but would be surprised if it encourages this. In HTTP world, a parameter consists of its name and value, both being Strings. > Besides I have no idea how I could make this > GET request independant from the order the HTML form generated. You shouldn't be required to do anything. In the Smalltalk web frameworks I know (Sst and Seaside mostly) an HTTPRequest object has a Dictionary like API for accessing parameters. Maybe something like "parameterAt: 'r'" should do the trick. > Maybe with Javascript? Javascript is the source of a lot of evil, but here, it is innocent like Cinderella. Normal HTTP processing still works without javascript and I hope this won't change any time soon. This is simple HTTP back and forth, no javascript required nor desired. > But I assume this simple scenario should work in teapot and I > just understand it correctly... Hmm. As I said, don't access url parameters by index, only by name. I am sure Teapot offers methods for that, in the most basic case it gives you a Dictionary or parameters, but most likely some wrapper that provides a Dictionary-esque access methods. Maybe this bit is a starting point (found here https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfulBuild/artifact/Teapot/Teapot.html): 3.1. Parameters in URLsThe URL pattern may contain named parameters (e.g., Query parameters and Form parameters can be accessed the same way as path parameters -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel [hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
Hi Joachim, my first steps in teapot used the named parameters (and manually sending the URL), but as soon as I used the HTML form, I had to switch to regex (I thought). Maybe this was wrong, but your hint concerning the 'req' will certainly yield new insights. I will try to find the req object and check what is going on with it... :-) thanks and kind regards Marcus
|
Am 04.08.15 um 13:34 schrieb Marcus Kemper via Pharo-users:
Hi Marcus, I am slowly getting what Teapot does... So you setup an Association with a String that matches the URL of an incoming request as key and its handler block as value. So you should be able to use "req at: #r" also when using the Regex as matching criteria. Once you confirm this, the ordering is neither relevant nor a problem for you and you can go forward. Just forget about indexed access to request data for the future. Please let us know if access by symbols works for you. Joachim -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
Hi Joachim,
thanks for your attention to this issue. I tried to change it to #a, #r or #kg, but this didn't work. It works with the following by leaving the '\?' out: GET:'\/bac\/a=(\d*)&r=(\d*.\d*)&kg=(\d*)' asRegex -> [:req | BloodAlcoholCalculator a:(req at:1) r:(req at:2) kg:(req at:3) ]; But it works only by manually submitting it from the address input field of the browser. So I guess there is a problem with handling the '\?'. I will investigate further! :-) Best Marcus |
In reply to this post by jtuchel
Hi Joachim,
thanks for your attention to this issue. I tried to change it to #a, #r or #kg, but this didn't work. It works with the following by leaving the '\?' out: GET:'\/bac\/a=(\d*)&r=(\d*.\d*)&kg=(\d*)' asRegex -> [:req | BloodAlcoholCalculator a:(req at:1) r:(req at:2) kg:(req at:3) ]; But it works only by manually submitting it from the address input field of the browser. So I guess there is a problem with handling the '\?'. I will investigate further! :-) Best Marcus -- View this message in context: http://forum.world.st/Teapot-and-Regex-tp4840893p4840921.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
In reply to this post by Pharo Smalltalk Users mailing list
Hi Marcus,
It seems you're trying to define a matcher on the query parameters. It's not going to work. An url consist of path a the query part. These are separeted by a question mark. http://localhost:1701/foo/bar?q1=xx&q2=yy In this example /foo/bar is the path, and q1 and q2 are the query params. When you define a route in Teapot you specify the path part (either with wildcards or with regexp). Teapot will select the matching route when a request comes in based on the path part, and it will parse the query part (in fact Zn does this), and make the query parameters accessible in the request object. For example GET: '/foo/bar' -> [:req | req at: #q1] This matches to an url whose path part is /foo/bar, even if there is no query part, or if it has many query parameters. In your example, you've defined the query part in the matcher, but since it is not part of the incoming url, you've got 404. But if you share what you're trying to accomplish I may be able to help. Attila |
Hi Attila,
many thanks for your explanation - now it works by simply putting: GET:'/bac/' -> [:req | BloodAlcoholCalculator a:(req at:#a) r:(req at:#r) kg:(req at:#kg) ]; So you and Joachim were both right... :-) That makes it even easier to work with teapot. Kind regards Marcus |
In reply to this post by Attila Magyar
Hi Attila,
many thanks for your explanation - now it works by simply putting: GET:'/bac/' -> [:req | BloodAlcoholCalculator a:(req at:#a) r:(req at:#r) kg:(req at:#kg) ]; So you and Joachim were both right... :-) That makes it even easier to work with teapot. Kind regards Marcus -- View this message in context: http://forum.world.st/Teapot-and-Regex-tp4840893p4840965.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
Am 05.08.15 um 05:44 schrieb mtk via Pharo-users:
Hi Marcus, good to hear you could make it work. Thankfully, Attila gave us the final explanation for the regex mystery ;-) So I guess it is best to stick with "normal" strings for the most part for several reasons: * performance: (matching strings is probably a lot faster than matching a regex) * security / stability: looking back at my own experiments with regular expressions, you "never know" what exact urls are really being served. You need to do extensive testing on which URLs match and which don't. Sure this is not true if you know regex very well ;-) Joachim -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
In reply to this post by Pharo Smalltalk Users mailing list
Oh, and Marcus:
Please check your mail program: I only see your mail text as an attachment, and on some mail readers (e.g. iPhone) it is not even properly displayed. It is hard to cite your text and answer in the way we're used to do on mailing lists... Joachim -- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel mailto:[hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 |
Good morning, Thanks for the hint. I will check the settings. Kind regards Marcus Oh, and Marcus: |
Free forum by Nabble | Edit this page |