Reads & decodes HTTP multipart/form-data requests.
Not implemented yet! :-(
- read-multipart-form-data request #!optional max-lengthprocedure
Implements the same interface as Intarweb's read-urlencoded-request-data.
- multipart-form-data-decode str-port-or-seq boundary #!optional max-lengthprocedure
Decodes a multipart/form-data encoded body. This procedure requires the boundary token information from the HTTP headers.
Returns an alist: a list of name, value pairs or name, multipart-file pairs if the value was created from an HTML Forms File Input.
- multipart-file? Xprocedure
Tests to see if the value (cdrs of the pairs returned from multipart-form-data-decode) is the result of an HTML Forms File Input.
- multipart-file-port Xprocedure
A port from which you can read the contents of the file.
- multipart-file-filename Xprocedure
The filename that the browser supplied for the data read from the port.
- multipart-file-headers Xprocedure
A list of HTTP style headers that can tell you about the Content-Type and encoding of the data read from the port.
Use the header procedures from intarweb to access the value returned.
Here we present a decoder that can decide whether to decode multipart/form-data or application/x-www-form-urlencoded data based on the request headers:
(use intarweb multipart-form-data) (define (read-request-data req) (let* ((content-type (header-values 'content-type (request-headers req))) (_ (assert (= 1 (length content-type)))) (content-type (car content-type)) (proc (case content-type ((application/x-www-form-urlencoded) read-urlencoded-request-data) ((multipart/form-data) read-multipart-form-data) (else (abort "Unable to decode these shenannigans!"))))) (proc req)))
Copyright (C) 2014, Andy Bennett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- 0.1, (2014/10/12) : Preliminary support for decoding multipart/form-data encoded POST bodies. Very slow and copies the (possibly large) data around a fair bit. Also, it doesn't currently limit the amount of data that the user can send, although we provide a parameter and API for it (http-multipart-request-data-limit)
- 0.2, (2019/01/17) : CHICKEN 5 port from David Ireland