 PRIVATE>
 
 : gemini ( url -- status meta body/f )
-    dup gemini-addr utf8 [
+    dup gemini-addr binary [
         gemini-tls
         send-request
         read-response


:: gemtext. ( base-url body -- )
    f "pre" [
        body [
            {
                { [ "```" ?head ] [ drop "pre" on ] }
                { [ "=>" ?head ] [ base-url gemini-link. ] }

}

: read-body ( -- body )
    [ 1024 read ] loop>array concat ;

: ?read-body ( status -- body/f )
    ?first CHAR: 2 = [ read-body ] [ f ] if ;

: read-response ( -- status meta body/f )
    readln utf8 decode "\r" ?tail drop [ blank? ] split1-when over ?read-body ;

: send-request ( url -- )
    present utf8 encode write B{ CHAR: \r CHAR: \n } write flush ;

: gemini-addr ( url -- addr )
    [ host>> ] [ port>> 1965 or ] bi <inet> ;
