relocate "get" logic. see message

this stumped me for quite a minute. this procedure sometimes needs to
halt execution to get input, like a server requesting input, or the
client asking for permission to follow cross site redirects. the
problem is if the get procedure is thought of as being part of the net
interface, and compartmentalized from the program loop, actually doing
that would require heavy use of continuations to go back and forth
across the boundary

i -do- think that the way i ultimately want to go in the end is using
continuations to halt execution, catch it in the user interface to get
input, and then continue. however, its a lot simpler and more
immediate to change where i'm drawing the line in the separation of
concerns. the continuations-based approach is enough of a diversion
that i haven't managed to get anything done for the last couple of hours.
This commit is contained in:
2025-09-05 15:11:28 -07:00
parent f5cfbe76ea
commit 37e19cb279
2 changed files with 26 additions and 26 deletions

27
net.rkt
View File

@@ -1,6 +1,6 @@
#lang racket
(provide get)
(provide request)
(require openssl)
(require net/url-string)
@@ -9,7 +9,7 @@
;; 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 (send-request url-str)
(define (request url-str)
(define url (string->url url-str))
(define-values (c-in c-out)
(ssl-connect (url-host url)
@@ -46,26 +46,3 @@
[else
(values (string->number status) meta)])))))
(define (get url-str)
(define (iter url-str depth)
(let-values ([(status header c-in) (send-request url-str)])
;; TODO there are bunch of other status codes to deal with for
;; compliance
(cond
;; clients MUST reject status codes outside of the 10-69 range
[(or (< status 10)
(> status 69))
(error "server returned invalid status code")]
;; 30-39 redirection
[(and (>= status 30)
(<= status 39))
(if (> depth 5)
(error "maximum redirection depth exceeded")
(iter header (sub1 depth)))]
[else
(values status header c-in)])))
(iter url-str 5))