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:
25
gem300.rkt
25
gem300.rkt
@@ -15,13 +15,36 @@
|
||||
;; global state for the url of the currently visited document
|
||||
(define current-url null)
|
||||
|
||||
(define (get url-str)
|
||||
(define (iter url-str depth)
|
||||
(let-values ([(status header c-in) (net: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))
|
||||
|
||||
(define (go-cmd url)
|
||||
(if (non-empty-string? url)
|
||||
(let ()
|
||||
(when (not (string-contains? url "://"))
|
||||
(set! url (string-append "gemini://" url)))
|
||||
|
||||
(let-values ([(status meta c-in) (net:get url)])
|
||||
(let-values ([(status meta c-in) (get url)])
|
||||
(let-values ([(doc) (gmi:parse (port->lines c-in))]
|
||||
[(db-in db-out) (make-pipe #f)])
|
||||
|
||||
|
Reference in New Issue
Block a user