source: project/wiki/eggref/4/multipart-form-data @ 37063

Last change on this file since 37063 was 37063, checked in by andyjpb, 10 months ago
File size: 4.3 KB
Line 
1[[tags: egg]]
2
3== multipart-form-data
4
5[[toc:]]
6
7=== Description
8
9Reads & decodes HTTP multipart/form-data requests.
10
11=== Source Code
12
13[[https://bitbucket.org/knodium/multipart-form-data]]
14
15=== Author
16
17[[/users/andyjpb|Andy Bennett]]
18
19=== Requirements
20
21[[intarweb]], [[comparse]], [[records]]
22
23=== API
24
25==== http-multipart-request-data-limit
26
27<parameter> http-multipart-request-data-limit</parameter>
28
29Not implemented yet! :-(
30
31==== read-multipart-form-data
32
33<procedure>(read-multipart-form-data request [max-length])</procedure>
34
35Implements the same interface as Intarweb's [[intarweb#read-urlencoded-request-data|read-urlencoded-request-data]].
36
37==== multipart-form-data-decode
38
39<procedure>(multipart-form-data-decode str-port-or-seq boundary [max-length])</procedure>
40
41Decodes a multipart/form-data encoded body. This procedure requires the
42boundary token information from the HTTP headers.
43
44Returns an alist: a list of name, value pairs or name, multipart-file pairs if
45the value was created from an HTML Forms File Input.
46
47==== multipart-file?
48
49<procedure>(multipart-file? X)</procedure>
50
51Tests to see if the value (cdrs of the pairs returned from
52{{multipart-form-data-decode}}) is the result of an HTML Forms File Input.
53
54==== multipart-file-port
55
56<procedure>(multipart-file-port X)</procedure>
57
58A port from which you can read the contents of the file.
59
60==== mutipart-file-filename
61
62<procedure>(multipart-file-filename X)</procedure>
63
64The filename that the browser supplied for the data read from the port.
65
66==== multipart-file-headers
67
68<procedure>(multipart-file-headers X)</procedure>
69
70A list of HTTP style headers that can tell you about the Content-Type and
71encoding of the data read from the port.
72
73Use the header procedures from [[intarweb]] to access the value returned.
74
75=== Examples
76
77==== 1
78Here we present a decoder that can decide whether to decode multipart/form-data
79or application/x-www-form-urlencoded data based on the request headers:
80
81        (use intarweb multipart-form-data)
82       
83        (define (read-request-data req)
84          (let* ((content-type (header-values 'content-type (request-headers req)))
85                 (_            (assert (= 1 (length content-type))))
86                 (content-type (car content-type))
87                 (proc         (case content-type
88                                 ((application/x-www-form-urlencoded)
89                                  read-urlencoded-request-data)
90                                 ((multipart/form-data)
91                                  read-multipart-form-data)
92                                 (else
93                                   (abort "Unable to decode these shenannigans!")))))
94            (proc req)))
95
96
97=== License
98
99  Copyright (C) 2014, Andy Bennett
100  All rights reserved.
101 
102  Redistribution and use in source and binary forms, with or without
103  modification, are permitted provided that the following conditions are met:
104 
105  Redistributions of source code must retain the above copyright notice, this
106  list of conditions and the following disclaimer.
107  Redistributions in binary form must reproduce the above copyright notice,
108  this list of conditions and the following disclaimer in the documentation
109  and/or other materials provided with the distribution.
110  Neither the name of the author nor the names of its contributors may be
111  used to endorse or promote products derived from this software without
112  specific prior written permission.
113 
114  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
115  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
116  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
117  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
118  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
119  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
120  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
121  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
122  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
123  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
124  POSSIBILITY OF SUCH DAMAGE.
125
126=== Version History
127* 0.1, (2014/10/12) : Preliminary support for decoding multipart/form-data
128encoded POST bodies. Very slow and copies the (possibly large) data around a
129fair bit. Also, it doesn't currently limit the amount of data that the user can
130send, although we provide a parameter and API for it
131(http-multipart-request-data-limit)
132* 0.2, (2019/01/17) : CHICKEN 5 port from David Ireland
Note: See TracBrowser for help on using the repository browser.