| 
									
										
										
										
											2009-01-19 19:01:13 -05:00
										 |  |  | ! Copyright (C) 2009 Doug Coleman. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2010-09-19 14:38:02 -04:00
										 |  |  | USING: accessors assocs continuations fry http.server io | 
					
						
							|  |  |  | io.encodings.ascii io.files io.files.unique | 
					
						
							| 
									
										
										
										
											2010-09-27 20:12:33 -04:00
										 |  |  | io.servers io.streams.duplex io.streams.string | 
					
						
							| 
									
										
										
										
											2010-09-19 14:38:02 -04:00
										 |  |  | kernel math.ranges mime.multipart multiline namespaces random | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  | sequences sorting strings threads tools.test ;
 | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | IN: mime.multipart.tests | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  | CONSTANT: separator1 "----WebKitFormBoundary6odjpVPXIighAE2L" | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  | CONSTANT: upload1 "------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" | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-19 19:01:13 -05:00
										 |  |  | : mime-test-stream ( -- stream )
 | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |    upload1 | 
					
						
							| 
									
										
										
										
											2009-01-19 19:01:13 -05:00
										 |  |  |    "mime" "test" make-unique-file ascii | 
					
						
							|  |  |  |    [ set-file-contents ] [ <file-reader> ] 2bi ;
 | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { } [ mime-test-stream [ ] with-input-stream ] unit-test | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { t } [ | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     mime-test-stream [ separator1 parse-multipart ] with-input-stream
 | 
					
						
							| 
									
										
										
										
											2009-01-26 18:29:50 -05:00
										 |  |  |     "file1" swap key?
 | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { t } [ | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     mime-test-stream [ separator1 parse-multipart ] with-input-stream
 | 
					
						
							| 
									
										
										
										
											2009-01-26 18:29:50 -05:00
										 |  |  |     "file1" swap key?
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { t } [ | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     mime-test-stream [ separator1 parse-multipart ] with-input-stream
 | 
					
						
							| 
									
										
										
										
											2013-03-23 17:35:01 -04:00
										 |  |  |     "file1" of filename>> "up.txt" =
 | 
					
						
							| 
									
										
										
										
											2008-11-21 23:10:58 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2009-01-20 16:45:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  | CONSTANT: separator2 "768de80194d942619886d23f1337aa15" | 
					
						
							|  |  |  | CONSTANT: upload2 "--768de80194d942619886d23f1337aa15\r\nContent-Disposition: form-data; name=\"text\"; filename=\"upload.txt\"\r\nContent-Type: text/plain\r\n\r\nhello\r\n--768de80194d942619886d23f1337aa15--\r\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     "upload.txt" | 
					
						
							|  |  |  |     H{ | 
					
						
							|  |  |  |         { "content-disposition" | 
					
						
							|  |  |  |           "form-data; name=\"text\"; filename=\"upload.txt\"" } | 
					
						
							|  |  |  |         { "content-type" "text/plain" } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | } [ | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     upload2 [ separator2 parse-multipart ] with-string-reader | 
					
						
							|  |  |  |     "text" of [ filename>> ] [ headers>> ] bi
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONSTANT: separator3 "3f116598c7f0431b9f98148ed235c822" | 
					
						
							|  |  |  | CONSTANT: upload3 "--3f116598c7f0431b9f98148ed235c822\r\nContent-Disposition: form-data; name=\"text\"; filename=\"upload.txt\"\r\n\r\nhello\r\n--3f116598c7f0431b9f98148ed235c822\r\nContent-Disposition: form-data; name=\"text2\"; filename=\"upload.txt\"\r\n\r\nhello\r\n--3f116598c7f0431b9f98148ed235c822--\r\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     { "text" "text2" } | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | } [ | 
					
						
							| 
									
										
										
										
											2014-10-29 14:34:08 -04:00
										 |  |  |     upload3 [ separator3 parse-multipart ] with-string-reader | 
					
						
							|  |  |  |     keys natural-sort | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-19 14:38:02 -04:00
										 |  |  | SYMBOL: mime-test-server | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-test-server ( quot -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         <http-server> | 
					
						
							|  |  |  |             f >>secure | 
					
						
							|  |  |  |             0 >>insecure | 
					
						
							|  |  |  |     ] dip with-threaded-server ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-server-port ( -- n )
 | 
					
						
							|  |  |  |     mime-test-server get insecure>> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : a-stream ( n -- stream )
 | 
					
						
							|  |  |  |     CHAR: a <string> <string-reader> ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { } [ | 
					
						
							| 
									
										
										
										
											2010-09-19 14:38:02 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |     ] with-test-server | 
					
						
							|  |  |  | ] unit-test |