]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/http/client/client-tests.factor
core: subseq-index? -> subseq-of?
[factor.git] / basis / http / client / client-tests.factor
index 7cda571681e84b214d9484b93904a7cdc12a2088..49b897180e86c942f75e17db7119fa77e1fb8a7c 100644 (file)
@@ -1,10 +1,8 @@
-USING: accessors io.sockets.secure http.client http.client.private http
-io.streams.string kernel namespaces sequences tools.test urls ;
+USING: accessors http http.client http.client.private
+io.streams.string kernel namespaces sequences splitting
+tools.test urls ;
 IN: http.client.tests
 
-{ "localhost" f } [ "localhost" parse-host ] unit-test
-{ "localhost" 8888 } [ "localhost:8888" parse-host ] unit-test
-
 { "foo.txt" } [ "http://www.paulgraham.com/foo.txt" download-name ] unit-test
 { "foo.txt" } [ "http://www.arc.com/foo.txt?xxx" download-name ] unit-test
 { "foo.txt" } [ "http://www.arc.com/foo.txt/" download-name ] unit-test
@@ -17,7 +15,7 @@ IN: http.client.tests
         { method "GET" }
         { version "1.1" }
         { cookies V{ } }
-        { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
+        { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
         { redirects 10 }
     }
 } [
@@ -32,7 +30,7 @@ IN: http.client.tests
         { method "GET" }
         { version "1.1" }
         { cookies V{ } }
-        { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
+        { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
         { redirects 10 }
     }
 } [
@@ -44,11 +42,15 @@ IN: http.client.tests
 { "DELETE" } [ "http://arc.com" <delete-request> method>> ] unit-test
 { "TRACE" } [ "http://concatenative.org" <trace-request> method>> ] unit-test
 { "OPTIONS" } [ "http://factorcode.org" <options-request> method>> ] unit-test
-{ t } [
-    "https://alice.sni.velox.ch" http-get nip
-    [ "Great!" swap subseq? ]
-    [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
-] unit-test
+
+! Do not re-enable this for the test suite.
+! We should replace this with a similar test that does not
+! hit the velox.ch website.
+! { t } [
+    ! "https://alice.sni.velox.ch" http-get nip
+    ! [ "Great!" subseq-of? ]
+    ! [ "TLS SNI Test Site: alice.sni.velox.ch" subseq-of? ] bi and
+! ] unit-test
 
 { t } [
     {
@@ -57,7 +59,7 @@ IN: http.client.tests
         "content-type: text/html; charset=UTF-8"
         "date: Wed, 12 Oct 2011 18:57:49 GMT"
         "server: Factor http.server"
-    } [ "\n" join ] [ "\r\n" join ] bi
+    } [ join-lines ] [ "\r\n" join ] bi
     [ [ read-response ] with-string-reader ] same?
 ] unit-test
 
@@ -191,6 +193,22 @@ CONSTANT: classic-proxy-settings H{
     ] with-variables
 ] unit-test
 
+{ URL" //localhost:3128" } [
+    { { "http.proxy" "//localhost:3128" } } [
+       "google.com" "GET" <client-request> ?default-proxy proxy-url>>
+    ] with-variables
+] unit-test
+
+{ URL" //localhost:3128" } [
+    "google.com" "GET" <client-request>
+    URL" //localhost:3128" >>proxy-url ?default-proxy proxy-url>>
+] unit-test
+
+{ URL" //localhost:3128" } [
+    "google.com" "GET" <client-request>
+    "//localhost:3128" >>proxy-url ?default-proxy proxy-url>>
+] unit-test
+
 { URL" http://proxysec.private:3128" } [
     classic-proxy-settings [
        "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
@@ -208,3 +226,14 @@ CONSTANT: classic-proxy-settings H{
        "http://www.google.com" "GET" <client-request> ?default-proxy
     ] with-variable
 ] [ invalid-proxy? ] must-fail-with
+
+! This url is misparsed bu request-url can fix it
+{ T{ url
+   { protocol "http" }
+   { host "www.google.com" }
+   { path "/" }
+   { port 80 }
+} } [ "www.google.com" request-url ] unit-test
+
+! This one is not fixable, leave it as it is
+{ T{ url } } [ "" request-url ] unit-test