1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs continuations fry http.server io
4 io.encodings.ascii io.files io.files.unique
5 io.servers.connection io.streams.duplex io.streams.string
6 kernel math.ranges mime.multipart multiline namespaces random
7 sequences strings threads tools.test ;
8 IN: mime.multipart.tests
10 : upload-separator ( -- seq )
11 "----WebKitFormBoundary6odjpVPXIighAE2L" ;
14 "------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file1\"; filename=\"up.txt\"\r\nContent-Type: text/plain\r\n\r\nuploaded!\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file2\"; filename=\"\"\r\n\r\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"file3\"; filename=\"\"\r\n\r\n\r\n------WebKitFormBoundary6odjpVPXIighAE2L\r\nContent-Disposition: form-data; name=\"text1\"\r\n\r\nlol\r\n------WebKitFormBoundary6odjpVPXIighAE2L--\r\n" ;
16 : mime-test-stream ( -- stream )
18 "mime" "test" make-unique-file ascii
19 [ set-file-contents ] [ <file-reader> ] 2bi ;
21 [ ] [ mime-test-stream [ ] with-input-stream ] unit-test
24 mime-test-stream [ upload-separator parse-multipart ] with-input-stream
29 mime-test-stream [ upload-separator parse-multipart ] with-input-stream
34 mime-test-stream [ upload-separator parse-multipart ] with-input-stream
35 "file1" swap at filename>> "up.txt" =
38 SYMBOL: mime-test-server
40 : with-test-server ( quot -- )
45 ] dip with-threaded-server ; inline
47 : test-server-port ( -- n )
48 mime-test-server get insecure>> ;
50 : a-stream ( n -- stream )
51 CHAR: a <string> <string-reader> ;