1 USING: http http.server http.client tools.test multiline
2 io.streams.string io.encodings.utf8 io.encodings.8-bit
3 io.encodings.binary io.encodings.string kernel arrays splitting
4 sequences assocs io.sockets db db.sqlite continuations urls
8 [ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test
10 [ "text/html" utf8 ] [ "text/html; charset=UTF-8" parse-content-type ] unit-test
12 [ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test
14 : lf>crlf "\n" split "\r\n" join ;
16 STRING: read-request-test-1
21 Content-type: application/octet-stream
28 { url T{ url { path "/bar" } } }
31 { header H{ { "some-header" "1; 2" } { "content-length" "4" } { "content-type" "application/octet-stream" } } }
32 { post-data T{ post-data { content "blah" } { raw "blah" } { content-type "application/octet-stream" } } }
36 read-request-test-1 lf>crlf [
41 STRING: read-request-test-1'
44 content-type: application/octet-stream
50 read-request-test-1' 1array [
51 read-request-test-1 lf>crlf
52 [ read-request ] with-string-reader
53 [ write-request ] with-string-writer
55 string-lines "\n" join
58 STRING: read-request-test-2
66 { url T{ url { host "www.sex.com" } { path "/bar" } } }
69 { header H{ { "host" "www.sex.com" } } }
73 read-request-test-2 lf>crlf [
78 STRING: read-request-test-3
83 [ read-request-test-3 lf>crlf [ read-request ] with-string-reader ]
84 [ "Bad request: URL" = ]
87 STRING: read-request-test-4
89 Host: "www.amazon.com"
94 read-request-test-4 lf>crlf [ read-request ] with-string-reader
98 STRING: read-response-test-1
99 HTTP/1.1 404 not found
100 Content-Type: text/html; charset=UTF-8
109 { message "not found" }
110 { header H{ { "content-type" "text/html; charset=UTF-8" } } }
112 { content-type "text/html" }
113 { content-charset utf8 }
116 read-response-test-1 lf>crlf
117 [ read-response ] with-string-reader
121 STRING: read-response-test-1'
122 HTTP/1.1 404 not found
123 content-type: text/html; charset=UTF-8
128 read-response-test-1' 1array [
129 read-response-test-1 lf>crlf
130 [ read-response ] with-string-reader
131 [ write-response ] with-string-writer
133 string-lines "\n" join
137 "rmid=732423sdfs73242; path=/; domain=.example.net; expires=Fri, 31-Dec-2010 23:59:59 GMT"
138 dup parse-set-cookie first unparse-set-cookie =
143 dup parse-set-cookie first unparse-set-cookie =
146 STRING: read-response-test-2
147 HTTP/1.1 200 Content follows
148 Set-Cookie: oo="bar; a=b"; httponly=yes; sid=123456
154 read-response-test-2 lf>crlf
155 [ read-response ] with-string-reader
159 STRING: read-response-test-3
160 HTTP/1.1 200 Content follows
161 Set-Cookie: oo="bar; a=b"; comment="your mom"; httponly=yes
167 read-response-test-3 lf>crlf
168 [ read-response ] with-string-reader
173 USING: http.server http.server.static furnace.sessions furnace.alloy
174 furnace.actions furnace.auth furnace.auth.login furnace.db http.client
175 io.servers.connection io.files io io.encodings.ascii
176 accessors namespaces threads
177 http.server.responses http.server.redirection furnace.redirection
178 http.server.dispatchers db.tuples ;
182 [ stop-this-server "Goodbye" "text/html" <content> ] >>display
183 "quit" add-responder ;
185 : test-db "test.db" temp-file sqlite-db ;
187 [ test-db drop delete-file ] ignore-errors
194 #! Return as soon as server is running.
205 "resource:basis/http/test" <static> >>default
206 "nested" add-responder
208 [ URL" redirect-loop" <temporary-redirect> ] >>display
209 "redirect-loop" add-responder
217 "resource:basis/http/test/foo.html" ascii file-contents
218 "http://localhost:1237/nested/foo.html" http-get nip =
221 [ "http://localhost:1237/redirect-loop" http-get nip ]
222 [ too-many-redirects? ] must-fail-with
225 "http://localhost:1237/quit" http-get nip
228 ! HTTP client redirect bug
233 <action> [ "quit" <temporary-redirect> ] >>display
234 "redirect" add-responder
242 "http://localhost:1237/redirect" http-get nip
247 [ "http://localhost:1237/quit" http-get 2drop ] ignore-errors
260 <action> "" add-responder
262 test-db <db-persistence>
269 : 404? [ download-failed? ] [ response>> code>> 404 = ] bi and ;
271 ! This should give a 404 not an infinite redirect loop
272 [ "http://localhost:1237/d/blah" http-get nip ] [ 404? ] must-fail-with
274 ! This should give a 404 not an infinite redirect loop
275 [ "http://localhost:1237/blah/" http-get nip ] [ 404? ] must-fail-with
277 [ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test
282 <action> [ [ "Hi" write ] "text/plain" <content> ] >>display
287 test-db <db-persistence>
294 [ "Hi" ] [ "http://localhost:1237/" http-get nip ] unit-test
296 [ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test
298 USING: html.components html.elements html.forms
299 xml xml.utilities validators
300 furnace furnace.conversations ;
308 [ a get-global "a" set-value ] >>init
309 [ [ <html> "a" <field> render </html> ] "text/html" <content> ] >>display
310 [ { { "a" [ v-integer ] } } validate-params ] >>validate
311 [ "a" value a set-global URL" " <redirect> ] >>submit
316 test-db <db-persistence>
325 : test-a string>xml "input" tag-named "value" swap at ;
328 "http://localhost:1237/" http-get
329 swap dup cookies>> "cookies" set session-id-key get-cookie
330 value>> "session-id" set test-a
334 H{ { "a" "4" } { "__u" "http://localhost:1237/" } } "session-id" get session-id-key associate assoc-union
335 "http://localhost:1237/" <post-request> "cookies" get >>cookies http-request nip test-a
338 [ 4 ] [ a get-global ] unit-test
342 H{ { "a" "xyz" } { "__u" "http://localhost:1237/" } } "session-id" get session-id-key associate assoc-union
343 "http://localhost:1237/" <post-request> "cookies" get >>cookies http-request nip test-a
346 [ 4 ] [ a get-global ] unit-test
348 [ "Goodbye" ] [ "http://localhost:1237/quit" http-get nip ] unit-test
351 [ f ] [ <404> dup clone "b" "a" set-header drop "a" header ] unit-test
352 [ f ] [ <404> dup clone "b" "a" <cookie> put-cookie drop "a" get-cookie ] unit-test