From 522d253c2ae1f822debd279e29ca56692b8397e5 Mon Sep 17 00:00:00 2001 From: w6vvn Date: Fri, 5 Sep 2025 18:18:14 -0700 Subject: [PATCH] standardize on storing urls as url structs internally instead of as strings --- gmi.rkt | 6 ++++-- net.rkt | 12 ++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gmi.rkt b/gmi.rkt index a77e9d8..912f387 100644 --- a/gmi.rkt +++ b/gmi.rkt @@ -3,9 +3,11 @@ (provide (contract-out [render (-> document? void?)] [parse (-> (listof string?) document?)] - [match-link (-> document? integer? (or/c string? #f))] + [match-link (-> document? integer? (or/c url? #f))] [struct document ((items (listof (or/c text? link? pre?))))])) +(require net/url-string) + ;; a gemtext document is represented as a list of structs, a struct ;; for each type of item in a document. (struct document (items)) @@ -22,7 +24,7 @@ (let ([split (string-split (substring line 2))]) (if (empty? split) (text line) - (link (car split) + (link (string->url (car split)) (if (>= (length split) 2) (string-join (cdr split)) (car split)) diff --git a/net.rkt b/net.rkt index c075859..a04e724 100644 --- a/net.rkt +++ b/net.rkt @@ -1,21 +1,17 @@ #lang racket -(provide request) +(provide (contract-out + [request (-> url? (values integer? string? input-port?))])) (require openssl) (require net/url-string) -;; sends a request to a gemini server, and returns the status, header, -;; and the input port for the rest of the body. -;; this procedure will fail if the response is malformed, however, it -;; is not up to it to validate the contents of the response. -(define (request url-str) - (define url (string->url url-str)) +(define (request url) (define-values (c-in c-out) (ssl-connect (url-host url) (or (url-port url) 1965))) - (write-string url-str c-out) + (write-string (url->string url) c-out) (write-string "\r\n" c-out) (define-values (status header)