Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - tardigrade

#1
I'd like to implement a REST server by running newlisp in http-only mode, and intercepting requests with "command-event".   However, the argument to command-event only contains the method, header and http version.  Is there a way to access the "raw" request body, and thereby gain access to the content of a PUT or POST request?



Thanks in advance,

Jeff
#2
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


"GET /foobar.html?this=that"

should be rewritten as


"GET /request.html?method=GET&url=foobar.html"

The preprocessing script looks like this:


(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) "")))))


while request.html is just this little snippet of JavaScript:


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


Strangely, when I start up newLISP as an HTTP daemon and point my browser to "foobar.html?this=that", I see



[size=150]Hello[/size]

this=that



Instead of



[size=150]Hello[/size]

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.