| 
									
										
										
										
											2009-04-07 04:37:29 -04:00
										 |  |  | USING: http http.server http.client http.client.private tools.test | 
					
						
							|  |  |  | multiline io.streams.string io.encodings.utf8 io.encodings.8-bit | 
					
						
							|  |  |  | io.encodings.binary io.encodings.string io.encodings.ascii kernel | 
					
						
							|  |  |  | arrays splitting sequences assocs io.sockets db db.sqlite | 
					
						
							|  |  |  | continuations urls hashtables accessors namespaces xml.data ;
 | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: http.tests | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-25 04:25:08 -04:00
										 |  |  | [ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "text/html" utf8 ] [ "text/html;  charset=UTF-8" parse-content-type ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-08 18:33:17 -04:00
										 |  |  | [ "text/html" utf8 ] [ "text/html; charset=\"utf-8\"" parse-content-type ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-25 04:25:08 -04:00
										 |  |  | [ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 01:34:02 -04:00
										 |  |  | : lf>crlf ( string -- string' ) "\n" split "\r\n" join ;
 | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | STRING: read-request-test-1 | 
					
						
							| 
									
										
										
										
											2008-06-12 19:53:53 -04:00
										 |  |  | POST /bar HTTP/1.1 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | Some-Header: 1
 | 
					
						
							|  |  |  | Some-Header: 2
 | 
					
						
							|  |  |  | Content-Length: 4
 | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | Content-type: application/octet-stream | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | blah | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |     T{ request | 
					
						
							| 
									
										
										
										
											2008-09-06 03:16:44 -04:00
										 |  |  |         { url T{ url { path "/bar" } } } | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |         { method "POST" } | 
					
						
							|  |  |  |         { version "1.1" } | 
					
						
							|  |  |  |         { header H{ { "some-header" "1; 2" } { "content-length" "4" } { "content-type" "application/octet-stream" } } } | 
					
						
							| 
									
										
										
										
											2009-01-21 20:55:25 -05:00
										 |  |  |         { post-data T{ post-data { data "blah" } { content-type "application/octet-stream" } } } | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |         { cookies V{ } } | 
					
						
							| 
									
										
										
										
											2009-07-09 20:02:15 -04:00
										 |  |  |         { redirects 10 } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  |     read-request-test-1 lf>crlf [ | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         read-request | 
					
						
							|  |  |  |     ] with-string-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-request-test-1' | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | POST /bar HTTP/1.1 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | content-length: 4
 | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | content-type: application/octet-stream | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | some-header: 1; 2
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | blah | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | read-request-test-1' 1array [ | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  |     read-request-test-1 lf>crlf | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     [ read-request ] with-string-reader | 
					
						
							|  |  |  |     [ write-request ] with-string-writer | 
					
						
							|  |  |  |     ! normalize crlf | 
					
						
							|  |  |  |     string-lines "\n" join
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-request-test-2 | 
					
						
							| 
									
										
										
										
											2008-06-12 19:53:53 -04:00
										 |  |  | HEAD  /bar   HTTP/1.1 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | Host: www.sex.com | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |     T{ request | 
					
						
							| 
									
										
										
										
											2008-09-06 06:12:28 -04:00
										 |  |  |         { url T{ url { host "www.sex.com" } { path "/bar" } } } | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |         { method "HEAD" } | 
					
						
							|  |  |  |         { version "1.1" } | 
					
						
							|  |  |  |         { header H{ { "host" "www.sex.com" } } } | 
					
						
							|  |  |  |         { cookies V{ } } | 
					
						
							| 
									
										
										
										
											2009-07-09 20:02:15 -04:00
										 |  |  |         { redirects 10 } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  |     read-request-test-2 lf>crlf [ | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         read-request | 
					
						
							|  |  |  |     ] with-string-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-01 18:22:39 -04:00
										 |  |  | STRING: read-request-test-3 | 
					
						
							|  |  |  | GET nested HTTP/1.0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-18 01:36:20 -04:00
										 |  |  | [ read-request-test-3 lf>crlf [ read-request ] with-string-reader ] | 
					
						
							| 
									
										
										
										
											2008-06-01 18:22:39 -04:00
										 |  |  | [ "Bad request: URL" = ] | 
					
						
							|  |  |  | must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-18 01:36:20 -04:00
										 |  |  | STRING: read-request-test-4 | 
					
						
							|  |  |  | GET /blah HTTP/1.0 | 
					
						
							|  |  |  | Host: "www.amazon.com" | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "www.amazon.com" ] | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     read-request-test-4 lf>crlf [ read-request ] with-string-reader | 
					
						
							|  |  |  |     "host" header | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | STRING: read-response-test-1 | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | HTTP/1.1 404 not found | 
					
						
							| 
									
										
										
										
											2008-06-12 04:50:20 -04:00
										 |  |  | Content-Type: text/html; charset=UTF-8 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | blah | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							| 
									
										
										
										
											2008-09-05 21:39:45 -04:00
										 |  |  |     T{ response | 
					
						
							|  |  |  |         { version "1.1" } | 
					
						
							|  |  |  |         { code 404 } | 
					
						
							|  |  |  |         { message "not found" } | 
					
						
							|  |  |  |         { header H{ { "content-type" "text/html; charset=UTF-8" } } } | 
					
						
							|  |  |  |         { cookies { } } | 
					
						
							|  |  |  |         { content-type "text/html" } | 
					
						
							|  |  |  |         { content-charset utf8 } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  |     read-response-test-1 lf>crlf | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     [ read-response ] with-string-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-response-test-1' | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | HTTP/1.1 404 not found | 
					
						
							| 
									
										
										
										
											2008-06-12 04:50:20 -04:00
										 |  |  | content-type: text/html; charset=UTF-8 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | read-response-test-1' 1array [ | 
					
						
							| 
									
										
										
										
											2008-11-24 21:26:29 -05:00
										 |  |  |     URL" http://localhost/" url set
 | 
					
						
							| 
									
										
										
										
											2008-04-23 01:53:42 -04:00
										 |  |  |     read-response-test-1 lf>crlf | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     [ read-response ] with-string-reader | 
					
						
							|  |  |  |     [ write-response ] with-string-writer | 
					
						
							|  |  |  |     ! normalize crlf | 
					
						
							|  |  |  |     string-lines "\n" join
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "rmid=732423sdfs73242; path=/; domain=.example.net; expires=Fri, 31-Dec-2010 23:59:59 GMT" | 
					
						
							| 
									
										
										
										
											2008-06-18 01:36:20 -04:00
										 |  |  |     dup parse-set-cookie first unparse-set-cookie =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "a=" | 
					
						
							|  |  |  |     dup parse-set-cookie first unparse-set-cookie =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-response-test-2 | 
					
						
							|  |  |  | HTTP/1.1 200 Content follows | 
					
						
							|  |  |  | Set-Cookie: oo="bar; a=b"; httponly=yes; sid=123456 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 2 ] [ | 
					
						
							|  |  |  |     read-response-test-2 lf>crlf | 
					
						
							|  |  |  |     [ read-response ] with-string-reader | 
					
						
							|  |  |  |     cookies>> length
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-response-test-3 | 
					
						
							|  |  |  | HTTP/1.1 200 Content follows | 
					
						
							|  |  |  | Set-Cookie: oo="bar; a=b"; comment="your mom"; httponly=yes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 1 ] [ | 
					
						
							|  |  |  |     read-response-test-3 lf>crlf | 
					
						
							|  |  |  |     [ read-response ] with-string-reader | 
					
						
							|  |  |  |     cookies>> length
 | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Live-fire exercise | 
					
						
							| 
									
										
										
										
											2009-05-16 01:29:21 -04:00
										 |  |  | USING: http.server.static furnace.sessions furnace.alloy | 
					
						
							|  |  |  | furnace.actions furnace.auth furnace.auth.login furnace.db | 
					
						
							|  |  |  | io.servers.connection io.files io.files.temp io.directories io | 
					
						
							|  |  |  | threads | 
					
						
							| 
									
										
										
										
											2008-06-17 06:25:21 -04:00
										 |  |  | http.server.responses http.server.redirection furnace.redirection | 
					
						
							| 
									
										
										
										
											2008-06-13 21:54:52 -04:00
										 |  |  | http.server.dispatchers db.tuples ;
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 01:34:02 -04:00
										 |  |  | : add-quit-action ( responder -- responder )
 | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  |     <action> | 
					
						
							| 
									
										
										
										
											2008-10-02 09:30:38 -04:00
										 |  |  |         [ stop-this-server "Goodbye" "text/html" <content> ] >>display | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  |     "quit" add-responder ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 01:34:02 -04:00
										 |  |  | : test-db-file ( -- path ) "test.db" temp-file ;
 | 
					
						
							| 
									
										
										
										
											2008-04-26 02:44:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 01:34:02 -04:00
										 |  |  | : test-db ( -- db ) test-db-file <sqlite-db> ;
 | 
					
						
							| 
									
										
										
										
											2008-10-02 17:37:04 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ test-db-file delete-file ] ignore-errors
 | 
					
						
							| 
									
										
										
										
											2008-05-01 17:24:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-26 02:44:45 -04:00
										 |  |  | test-db [ | 
					
						
							| 
									
										
										
										
											2008-06-13 21:54:52 -04:00
										 |  |  |     init-furnace-tables | 
					
						
							| 
									
										
										
										
											2008-04-26 02:44:45 -04:00
										 |  |  | ] with-db | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | : test-httpd ( responder -- )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         main-responder set
 | 
					
						
							|  |  |  |         <http-server> | 
					
						
							|  |  |  |             0 >>insecure | 
					
						
							|  |  |  |             f >>secure | 
					
						
							|  |  |  |         dup start-server* | 
					
						
							|  |  |  |         sockets>> first addr>> port>> | 
					
						
							|  |  |  |     ] with-scope "port" set ;
 | 
					
						
							| 
									
										
										
										
											2008-06-25 17:58:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     <dispatcher> | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  |         <dispatcher> | 
					
						
							| 
									
										
										
										
											2009-02-15 20:53:21 -05:00
										 |  |  |             "vocab:http/test" <static> >>default | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |         "nested" add-responder | 
					
						
							|  |  |  |         <action> | 
					
						
							|  |  |  |             [ URL" redirect-loop" <temporary-redirect> ] >>display | 
					
						
							|  |  |  |         "redirect-loop" add-responder | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     test-httpd | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | : add-port ( url -- url' )
 | 
					
						
							|  |  |  |     >url clone "port" get >>port ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | [ t ] [ | 
					
						
							| 
									
										
										
										
											2009-02-15 20:53:21 -05:00
										 |  |  |     "vocab:http/test/foo.html" ascii file-contents | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     "http://localhost/nested/foo.html" add-port http-get nip =
 | 
					
						
							| 
									
										
										
										
											2008-04-14 05:34:26 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "http://localhost/redirect-loop" add-port http-get nip ] | 
					
						
							| 
									
										
										
										
											2008-04-22 16:37:49 -04:00
										 |  |  | [ too-many-redirects? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | [ "Goodbye" ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     "http://localhost/quit" add-port http-get nip
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-04 17:56:41 -04:00
										 |  |  | ! HTTP client redirect bug | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     <dispatcher> | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							|  |  |  |         <action> [ "quit" <temporary-redirect> ] >>display | 
					
						
							|  |  |  |         "redirect" add-responder | 
					
						
							| 
									
										
										
										
											2008-09-04 17:56:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     test-httpd | 
					
						
							| 
									
										
										
										
											2008-09-04 17:56:41 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "Goodbye" ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     "http://localhost/redirect" add-port http-get nip
 | 
					
						
							| 
									
										
										
										
											2008-09-04 17:56:41 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     [ "http://localhost/quit" add-port http-get 2drop ] ignore-errors
 | 
					
						
							| 
									
										
										
										
											2008-09-04 17:56:41 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | ! Dispatcher bugs | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     <dispatcher> | 
					
						
							|  |  |  |         <action> <protected> | 
					
						
							|  |  |  |         "Test" <login-realm> | 
					
						
							|  |  |  |         <sessions> | 
					
						
							|  |  |  |         "" add-responder | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  |         <dispatcher> | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |             <action> "" add-responder | 
					
						
							|  |  |  |         "d" add-responder | 
					
						
							|  |  |  |     test-db <db-persistence> | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     test-httpd | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 01:34:02 -04:00
										 |  |  | : 404? ( response -- ? ) [ download-failed? ] [ response>> code>> 404 = ] bi and ;
 | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! This should give a 404 not an infinite redirect loop | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "http://localhost/d/blah" add-port http-get nip ] [ 404? ] must-fail-with | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! This should give a 404 not an infinite redirect loop | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "http://localhost/blah/" add-port http-get nip ] [ 404? ] must-fail-with | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     <dispatcher> | 
					
						
							|  |  |  |         <action> [ [ "Hi" write ] "text/plain" <content> ] >>display | 
					
						
							|  |  |  |         "Test" <login-realm> | 
					
						
							|  |  |  |         <sessions> | 
					
						
							|  |  |  |         "" add-responder | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							|  |  |  |     test-db <db-persistence> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test-httpd | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "Hi" ] [ "http://localhost/" add-port http-get nip ] unit-test | 
					
						
							| 
									
										
										
										
											2008-04-25 04:23:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-31 21:54:49 -05:00
										 |  |  | USING: html.components html.forms | 
					
						
							| 
									
										
										
										
											2009-02-05 22:17:03 -05:00
										 |  |  | xml xml.traversal validators | 
					
						
							| 
									
										
										
										
											2008-07-10 00:41:45 -04:00
										 |  |  | furnace furnace.conversations ;
 | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: a | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     <dispatcher> | 
					
						
							|  |  |  |         <action> | 
					
						
							|  |  |  |             [ a get-global "a" set-value ] >>init | 
					
						
							| 
									
										
										
										
											2009-02-01 03:02:09 -05:00
										 |  |  |             [ [ "<html>" write "a" <field> render "</html>" write ] "text/html" <content> ] >>display | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |             [ { { "a" [ v-integer ] } } validate-params ] >>validate | 
					
						
							|  |  |  |             [ "a" value a set-global URL" " <redirect> ] >>submit | 
					
						
							|  |  |  |         <conversations> | 
					
						
							|  |  |  |         <sessions> | 
					
						
							|  |  |  |         >>default | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							|  |  |  |     test-db <db-persistence> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test-httpd | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 3 a set-global
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-31 21:54:49 -05:00
										 |  |  | : test-a ( xml -- value )
 | 
					
						
							|  |  |  |     string>xml body>> "input" deep-tag-named "value" attr ;
 | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "3" ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     "http://localhost/" add-port http-get | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  |     swap dup cookies>> "cookies" set session-id-key get-cookie | 
					
						
							|  |  |  |     value>> "session-id" set test-a | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "4" ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         "4" "a" set
 | 
					
						
							|  |  |  |         "http://localhost" add-port "__u" set
 | 
					
						
							|  |  |  |         "session-id" get session-id-key set
 | 
					
						
							|  |  |  |     ] H{ } make-assoc
 | 
					
						
							|  |  |  |     "http://localhost/" add-port <post-request> "cookies" get >>cookies http-request nip test-a | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 4 ] [ a get-global ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Test flash scope | 
					
						
							|  |  |  | [ "xyz" ] [ | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  |     [ | 
					
						
							|  |  |  |         "xyz" "a" set
 | 
					
						
							|  |  |  |         "http://localhost" add-port "__u" set
 | 
					
						
							|  |  |  |         "session-id" get session-id-key set
 | 
					
						
							|  |  |  |     ] H{ } make-assoc
 | 
					
						
							|  |  |  |     "http://localhost/" add-port <post-request> "cookies" get >>cookies http-request nip test-a | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ 4 ] [ a get-global ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 23:05:22 -04:00
										 |  |  | [ "Goodbye" ] [ "http://localhost/quit" add-port http-get nip ] unit-test | 
					
						
							| 
									
										
										
										
											2008-06-16 02:35:06 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Test cloning | 
					
						
							|  |  |  | [ f ] [ <404> dup clone "b" "a" set-header drop "a" header ] unit-test | 
					
						
							|  |  |  | [ f ] [ <404> dup clone "b" "a" <cookie> put-cookie drop "a" get-cookie ] unit-test | 
					
						
							| 
									
										
										
										
											2009-02-12 23:39:26 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Test basic auth | 
					
						
							|  |  |  | [ "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" ] [ <request> "Aladdin" "open sesame" set-basic-auth "Authorization" header ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-07 04:37:29 -04:00
										 |  |  | ! Test a corner case with static responder | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     <dispatcher> | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							|  |  |  |         "vocab:http/test/foo.html" <static> >>default | 
					
						
							|  |  |  |     test-httpd | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "http://localhost/" add-port http-get nip
 | 
					
						
							|  |  |  |     "vocab:http/test/foo.html" ascii file-contents =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2009-02-12 23:39:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-07 05:19:21 -04:00
										 |  |  | [ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Check behavior of 307 redirect (reported by Chris Double) | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     <dispatcher> | 
					
						
							|  |  |  |         add-quit-action | 
					
						
							|  |  |  |         <action> | 
					
						
							|  |  |  |             [ "b" <temporary-redirect> ] >>submit | 
					
						
							|  |  |  |         "a" add-responder | 
					
						
							|  |  |  |         <action> | 
					
						
							|  |  |  |             [ | 
					
						
							|  |  |  |                 request get post-data>> data>> "data" =
 | 
					
						
							|  |  |  |                 [ "OK" "text/plain" <content> ] [ "OOPS" throw ] if
 | 
					
						
							|  |  |  |             ] >>submit | 
					
						
							|  |  |  |         "b" add-responder | 
					
						
							|  |  |  |     test-httpd | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "OK" ] [ "data" "http://localhost/a" add-port http-post nip ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-09 09:18:26 -04:00
										 |  |  | ! Check that download throws errors (reported by Chris Double) | 
					
						
							| 
									
										
										
										
											2009-04-13 16:21:16 -04:00
										 |  |  | [ | 
					
						
							|  |  |  |     "resource:temp" [ | 
					
						
							|  |  |  |         "http://localhost/tweet_my_twat" add-port download | 
					
						
							|  |  |  |     ] with-directory | 
					
						
							|  |  |  | ] must-fail | 
					
						
							| 
									
										
										
										
											2009-04-09 09:18:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test |