[Lispweb] Body parsing
Richard Newman
r.newman at reading.ac.uk
Sun Apr 3 18:12:02 CDT 2005
Hello list,
I'm new here, so hi! I've been hacking away with Araneida and Wilbur,
doing assorted Semantic Web Lispy stuff. I have a
question/suggestion/hack relating to Araneida that I'd like to throw up
in the air.
(Inline Lisp is surrounded by _underscores_ for clarity.)
The Araneida _request_ class has a body for POST requests.
_read-request-from-stream_ parses the HTTP body into an assoc list with
the following line (line 27, daemon.lisp):
(parsed-body (if body (parse-body body '(#\&) len) nil))
This is perfectly sane behaviour for x-www-form-urlencoded POST
bodies (e.g. first=value&second=value). However, for all other bodies
it is destructive and nonsensical (particularly XML, which uses =).
Unfortunately, I'm working with those other bodies -- e.g.
application/rdf+xml.
My initial hack was to put in a simple test on the Content-Type
header:
(parsed-body (if body
;; Use member on the raw assoc list to make sure we
catch requests
;; with multiple Content-Types.
(if (member "application/x-www-form-urlencoded"
(cdr (assoc :content-type headers)) :test #'string=)
(parse-body body '(#\&) len)
body)
nil))
i.e. only parse the body if we have form-encoded data; otherwise just
use the body string (one could also url-unencode the body string). This
split has the unfortunate side effect that for some requests
_(request-body request)_ will return an assoc list, and sometimes a
string. I don't know what consequences this would have on existing
code. _(stringp)_ is one remedy; another would be to provide
_body-data_ and _body-parsed_ (or similar names) slots on _request_,
rather than just _body_. I would think that if Araneida-based
applications are using the parsed data (and it's valid/correct) then
their clients must be sending the correct headers (e.g. wget sends
x-www-form-urlencoded by default), so putting this check in wouldn't
break anything, but I might be wrong.
Any thoughts, anyone?
Regards,
-Richard
http://www.holygoat.co.uk/blog
More information about the lispweb
mailing list