strange behavior with command-event?
Posted: Tue Jan 26, 2010 6:30 pm
I'm a newcomer to newLISP. I've been playing around with url-rewriting using command-event, and ran into a behavior I wasn't expecting. My intention was to redirect all http requests to "request.html", parsing the http method and the url (minus the query string, if any) out of the original request and putting them into a query string in the new request. Thus
should be rewritten as
The preprocessing script looks like this:
while request.html is just this little snippet of JavaScript:
Strangely, when I start up newLISP as an HTTP daemon and point my browser to "foobar.html?this=that", I see
Hello
this=that
Instead of
Hello
method=GET
page=foobar.html
as I expect. In other words, the base url is correctly translated from "foobar.html" to "request.html", but the original query parameters are being passed instead of the new ones.
Can anyone explain:
(1) Why does command-event behave like this?
(2) How can I rewrite the query parameters?
I'd be most grateful for any advice.
Code: Select all
"GET /foobar.html?this=that"
Code: Select all
"GET /request.html?method=GET&url=foobar.html"
Code: Select all
(command-event (fn (str)
(local (method url page)
(begin
(map set '(method url) (0 2 (parse str )))
(if (find "?" url) (set 'page ((parse url "?") 0)))
(join (list "GET /request.html?method=" method "&page=" page) "")))))
Code: Select all
<html>
<body>
<h1>Hello</h1>
<script type="text/javascript">
query = document.location.href.split("?")[1]
vars = query.split("&")
for( i = 0; i < vars.length; i++ )
document.write( vars[i] + "<br>" )
</script>
</body>
</html>
Hello
this=that
Instead of
Hello
method=GET
page=foobar.html
as I expect. In other words, the base url is correctly translated from "foobar.html" to "request.html", but the original query parameters are being passed instead of the new ones.
Can anyone explain:
(1) Why does command-event behave like this?
(2) How can I rewrite the query parameters?
I'd be most grateful for any advice.