| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | USING: http tools.test multiline tuple-syntax | 
					
						
							| 
									
										
										
										
											2008-04-14 05:34:26 -04:00
										 |  |  | io.streams.string kernel arrays splitting sequences | 
					
						
							|  |  |  | assocs io.sockets ;
 | 
					
						
							| 
									
										
										
										
											2008-03-01 17:00:45 -05:00
										 |  |  | IN: http.tests | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "hello%20world" ] [ "hello world" url-encode ] unit-test | 
					
						
							|  |  |  | [ "hello world" ] [ "hello%20world" url-decode ] unit-test | 
					
						
							|  |  |  | [ "~hello world" ] [ "%7ehello+world" url-decode ] unit-test | 
					
						
							| 
									
										
										
										
											2008-03-17 05:31:13 -04:00
										 |  |  | [ f ] [ "%XX%XX%XX" url-decode ] unit-test | 
					
						
							|  |  |  | [ f ] [ "%XX%XX%X" url-decode ] unit-test | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "hello world"   ] [ "hello+world"    url-decode ] unit-test | 
					
						
							|  |  |  | [ "hello world"   ] [ "hello%20world"  url-decode ] unit-test | 
					
						
							|  |  |  | [ " ! "           ] [ "%20%21%20"      url-decode ] unit-test | 
					
						
							|  |  |  | [ "hello world"   ] [ "hello world%"   url-decode ] unit-test | 
					
						
							|  |  |  | [ "hello world"   ] [ "hello world%x"  url-decode ] unit-test | 
					
						
							|  |  |  | [ "hello%20world" ] [ "hello world"    url-encode ] unit-test | 
					
						
							|  |  |  | [ "%20%21%20"     ] [ " ! "            url-encode ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-01 19:38:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | [ "\u001234hi\u002045" ] [ "\u001234hi\u002045" url-encode url-decode ] unit-test | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-03 03:19:36 -05:00
										 |  |  | [ "/" ] [ "http://foo.com" url>path ] unit-test | 
					
						
							|  |  |  | [ "/" ] [ "http://foo.com/" url>path ] unit-test | 
					
						
							|  |  |  | [ "/bar" ] [ "http://foo.com/bar" url>path ] unit-test | 
					
						
							|  |  |  | [ "/bar" ] [ "/bar" url>path ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | STRING: read-request-test-1 | 
					
						
							|  |  |  | GET http://foo/bar HTTP/1.1 | 
					
						
							|  |  |  | Some-Header: 1
 | 
					
						
							|  |  |  | Some-Header: 2
 | 
					
						
							|  |  |  | Content-Length: 4
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | blah | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     TUPLE{ request | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         port: 80
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         method: "GET" | 
					
						
							| 
									
										
										
										
											2008-03-03 03:19:36 -05:00
										 |  |  |         path: "/bar" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         query: H{ } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         version: "1.1" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         header: H{ { "some-header" "1; 2" } { "content-length" "4" } } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         post-data: "blah" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         cookies: V{ } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     read-request-test-1 [ | 
					
						
							|  |  |  |         read-request | 
					
						
							|  |  |  |     ] with-string-reader | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-request-test-1' | 
					
						
							| 
									
										
										
										
											2008-03-03 03:19:36 -05:00
										 |  |  | GET /bar HTTP/1.1 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | content-length: 4
 | 
					
						
							| 
									
										
										
										
											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 [ | 
					
						
							|  |  |  |     read-request-test-1 | 
					
						
							|  |  |  |     [ read-request ] with-string-reader | 
					
						
							|  |  |  |     [ write-request ] with-string-writer | 
					
						
							|  |  |  |     ! normalize crlf | 
					
						
							|  |  |  |     string-lines "\n" join
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STRING: read-request-test-2 | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  | HEAD  http://foo/bar   HTTP/1.1 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  | Host: www.sex.com | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     TUPLE{ request | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         port: 80
 | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         method: "HEAD" | 
					
						
							| 
									
										
										
										
											2008-03-03 03:19:36 -05:00
										 |  |  |         path: "/bar" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         query: H{ } | 
					
						
							|  |  |  |         version: "1.1" | 
					
						
							|  |  |  |         header: H{ { "host" "www.sex.com" } } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         host: "www.sex.com" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         cookies: V{ } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     read-request-test-2 [ | 
					
						
							|  |  |  |         read-request | 
					
						
							|  |  |  |     ] 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-02-25 15:53:18 -05:00
										 |  |  | Content-Type: text/html | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | blah | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     TUPLE{ response | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         version: "1.1" | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |         code: 404
 | 
					
						
							|  |  |  |         message: "not found" | 
					
						
							| 
									
										
										
										
											2008-02-29 01:57:38 -05:00
										 |  |  |         header: H{ { "content-type" "text/html" } } | 
					
						
							|  |  |  |         cookies: V{ } | 
					
						
							| 
									
										
										
										
											2008-02-25 15:53:18 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | ] [ | 
					
						
							|  |  |  |     read-response-test-1 | 
					
						
							|  |  |  |     [ 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-02-25 15:53:18 -05:00
										 |  |  | content-type: text/html | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | read-response-test-1' 1array [ | 
					
						
							|  |  |  |     read-response-test-1 | 
					
						
							|  |  |  |     [ 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" | 
					
						
							|  |  |  |     dup parse-cookies unparse-cookies =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Live-fire exercise | 
					
						
							|  |  |  | USING: http.server http.server.static http.server.actions | 
					
						
							|  |  |  | http.client io.server io.files io accessors namespaces threads | 
					
						
							|  |  |  | io.encodings.ascii ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ ] [ | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         <dispatcher> | 
					
						
							| 
									
										
										
										
											2008-04-14 05:34:26 -04:00
										 |  |  |             <action> | 
					
						
							|  |  |  |                 [ stop-server "text/html" <content> [ "Goodbye" write ] >>body ] >>display | 
					
						
							|  |  |  |             "quit" add-responder | 
					
						
							|  |  |  |             <dispatcher> | 
					
						
							|  |  |  |                 "extra/http/test" resource-path <static> >>default | 
					
						
							|  |  |  |             "nested" add-responder | 
					
						
							| 
									
										
										
										
											2008-03-11 04:39:09 -04:00
										 |  |  |         main-responder set
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         [ 1237 httpd ] "HTTPD test" spawn drop
 | 
					
						
							|  |  |  |     ] with-scope
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "extra/http/test/foo.html" resource-path ascii file-contents | 
					
						
							| 
									
										
										
										
											2008-04-14 05:34:26 -04:00
										 |  |  |     "http://localhost:1237/nested/foo.html" http-get =
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Try with a slightly malformed request | 
					
						
							|  |  |  | [ t ] [ | 
					
						
							|  |  |  |     "localhost" 1237 <inet> ascii <client> [ | 
					
						
							|  |  |  |         "GET nested HTTP/1.0\r\n" write flush
 | 
					
						
							|  |  |  |         "\r\n" write flush
 | 
					
						
							|  |  |  |         readln drop
 | 
					
						
							|  |  |  |         read-header USE: prettyprint | 
					
						
							|  |  |  |     ] with-stream dup . "location" swap at "/" head?
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:21:20 -05:00
										 |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ "Goodbye" ] [ | 
					
						
							|  |  |  |     "http://localhost:1237/quit" http-get | 
					
						
							|  |  |  | ] unit-test |