[tbnl-devel] verbatim post parameter access?
Zach Beane
xach at xach.com
Mon Feb 21 16:59:44 UTC 2005
On Mon, Feb 21, 2005 at 05:10:59PM +0100, Edi Weitz wrote:
> Hi Zach!
>
> No, at the moment you can't. CONTENT-STREAM is not documented because
> it's of no use once the request object has been created. I think the
> best way to implement this would be to add a new slot (something like
> "RAW-POST-DATA") to the request object and only fill it if some
> special variable which usually is NIL has a true value. What do you
> think?
Sounds good to me.
> If you want to work on this the meat of it should be around line 110
> in request.lisp and you should also decide if you want to do the same
> thing for multipart/form-data POST requests.
>
> I can also do this but probably not this week - I'm pretty busy. So,
> clean patches including documentation are preferred... :)
Ok, attached is a patch. I have tested it for a few cases and it seems
to work.
Zach
-------------- next part --------------
Only in tbnl-0.3.10: cookie.fasl
diff -ur tbnl-0.3.10-orig/doc/index.html tbnl-0.3.10/doc/index.html
--- tbnl-0.3.10-orig/doc/index.html 2005-01-24 06:48:13.000000000 -0500
+++ tbnl-0.3.10/doc/index.html 2005-02-21 11:54:29.000000000 -0500
@@ -86,6 +86,7 @@
<li><a href='#get-parameters'><code>get-parameters</code></a>
<li><a href='#post-parameter'><code>post-parameter</code></a>
<li><a href='#post-parameters'><code>post-parameters</code></a>
+ <li><a href='#raw-post-data'><code>raw-post-data</code></a>
<li><a href='#parameter'><code>parameter</code></a>
<li><a href='#header-in'><code>header-in</code></a>
<li><a href='#headers-in'><code>headers-in</code></a>
@@ -216,6 +217,7 @@
<li><a href='#read-from-string*'><code>read-from-string*</code></a>
<li><a href='#http-token-p'><code>http-token-p</code></a>
<li><a href='#*tmp-directory*'><code>*tmp-directory*</code></a>
+ <li><a href='#*save-raw-post-data-p*'><code>*save-raw-post-data-p*</code></a>
</ol>
<li><a href='#debug'>Debugging TBNL applications</a>
<ol>
@@ -624,6 +626,16 @@
</blockquote>
<p><br>[Function]
+<br><a class=none name="raw-post-data"><b>raw-post-data</b> <tt>&optional</tt> <i>request</i> => <i>string</i>
+
+<blockquote><br>
+If <a
+href="#*save-raw-post-data-p*"><code>*SAVE-RAW-POST-DATA-P*</code></a> is
+<i>true</i> and the request is a POST request, returns the raw body of
+the request, otherwise returns nil.
+</blockquote>
+
+<p><br>[Function]
<br><a class=none name="parameter"><b>parameter</b> <i>name <tt>&optional</tt> request</i> => <i>string</i></a>
<blockquote><br>
@@ -1490,6 +1502,16 @@
This should be a pathname denoting a directory where temporary files can be stored. It is used for file uploads.
</blockquote>
+<p><br>[Special variable]
+<br><a class=none
+name="*save-raw-post-data-p*"><b>*save-raw-post-data-p*</b></a>
+
+<blockquote><br>
+If this variable is set to a <i>true</i> value (the default is
+<code>NIL</code>), when a POST request is received, the raw body is
+saved, and may be retrieved with <a
+href="#raw-post-data"><code>RAW-POST-DATA</code></a>. </blockquote>
+
<h4><a class=none name="debug">Debugging TBNL applications</a></h4>
If you want to debug your TBNL applications it is recommend that you start Apache (i.e. the <code>httpd</code> binary) with the <code>-X</code> command-line option. Then set <a href="#*debug-mode*"><code>*DEBUG-MODE*</code></a> to a <em>true</em> value and poke around in the listener. Good luck... :)
Only in tbnl-0.3.10/doc: index.html~
Only in tbnl-0.3.10: html.fasl
Only in tbnl-0.3.10: log.fasl
Only in tbnl-0.3.10: modlisp.fasl
Only in tbnl-0.3.10: packages.fasl
diff -ur tbnl-0.3.10-orig/packages.lisp tbnl-0.3.10/packages.lisp
--- tbnl-0.3.10-orig/packages.lisp 2005-01-24 06:50:46.000000000 -0500
+++ tbnl-0.3.10/packages.lisp 2005-02-21 11:31:57.000000000 -0500
@@ -46,6 +46,7 @@
#:*lisp-warnings-log-level*
#:*listener*
#:*log-lisp-backtraces-p*
+ #:*save-raw-post-data-p*
#:*log-lisp-errors-p*
#:*log-lisp-warnings-p*
#:*log-prefix*
@@ -130,6 +131,7 @@
#:get-parameter
#:get-parameters
#:handle-if-modified-since
+ #:raw-post-data
#:header-in
#:headers-in
#:header-out
Only in tbnl-0.3.10: packages.lisp~
Only in tbnl-0.3.10: reply.fasl
Only in tbnl-0.3.10: request.fasl
diff -ur tbnl-0.3.10-orig/request.lisp tbnl-0.3.10/request.lisp
--- tbnl-0.3.10-orig/request.lisp 2005-01-24 06:50:46.000000000 -0500
+++ tbnl-0.3.10/request.lisp 2005-02-21 11:57:38.000000000 -0500
@@ -50,7 +50,10 @@
(session :initform nil
:accessor session
:documentation "The session object associated with this
-request."))
+request.")
+ (raw-post-data :initform nil
+ :documentation "The raw string sent as the body of a
+POST request, populated only if *SAVE-RAW-POST-DATA-P* is non-nil."))
(:documentation "Objects of this class hold all the information
about an incoming request. They are created automatically by TBNL and
can be accessed by the corresponding handler."))
@@ -114,6 +117,8 @@
(let ((content (make-string (parse-integer content-length
:junk-allowed t))))
(read-sequence content content-stream)
+ (when *save-raw-post-data-p*
+ (setf (slot-value request 'raw-post-data) content))
content)))))
((starts-with-p content-type "multipart/form-data;" :test #'char-equal)
(handler-case
@@ -309,3 +314,6 @@
(setf (return-code) +http-not-modified+)
(throw 'tbnl-handler-done nil))
(values)))
+
+(defun raw-post-data (&optional (request *request*))
+ (slot-value request 'raw-post-data))
Only in tbnl-0.3.10: request.lisp.orig
Only in tbnl-0.3.10: request.lisp~
Only in tbnl-0.3.10: rfc2388.fasl
Only in tbnl-0.3.10: session.fasl
Only in tbnl-0.3.10: specials.fasl
diff -ur tbnl-0.3.10-orig/specials.lisp tbnl-0.3.10/specials.lisp
--- tbnl-0.3.10-orig/specials.lisp 2005-01-24 06:50:46.000000000 -0500
+++ tbnl-0.3.10/specials.lisp 2005-02-21 11:26:27.000000000 -0500
@@ -182,6 +182,10 @@
occurs. Will only have effect of *LOG-LISP-ERRORS-P* or
*LOG-LISP-BACKTRACES* are also true.")
+(defvar *save-raw-post-data-p* nil
+ "Whether the body of a POST request is made available through
+RAW-POST-DATA.")
+
(defvar-unbound *command*
"The current request as read from Apache/mod_lisp, converted into an
alist.")
Only in tbnl-0.3.10: specials.lisp~
Only in tbnl-0.3.10: util.fasl
More information about the Tbnl-devel
mailing list