standardize on storing urls as url structs internally instead of as strings

This commit is contained in:
2025-09-05 18:18:14 -07:00
parent bd3f048595
commit 522d253c2a
2 changed files with 8 additions and 10 deletions

View File

@@ -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))

12
net.rkt
View File

@@ -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)