M protocols/gemini-protocol.rkt => protocols/gemini-protocol.rkt +10 -1
@@ 3,7 3,8 @@
(require net/url
openssl
racket/pretty
- racket/struct)
+ racket/struct
+ "../config.rkt")
(define gemini-default-port 1965)
@@ 148,10 149,14 @@
(error 'gemini-request "too many redirects"))
(define gc (gemini-conn-open url))
(write-out (gemini-conn-out gc) url)
+ (when (debug-mode?)
+ (printf "--- REQUEST ---~n~n~a~n~n---------------~n~n" url))
(define response
(begin0
(gemini-recv! gc)
(gemini-conn-close! gc)))
+ (when (debug-mode?)
+ (printf "--- RESPONSE ---~n~n~a~n~n---------------~n~n" response))
(if (and (member (gemini-response-status response) (list 30 31)) fr)
(gemini-request (gemini-response-meta response) #:follow-redirects #t (add1 how-many-redirects-so-far))
response))
@@ 159,6 164,9 @@
(define (gemini-valid-status-code status)
(list? (member status '(10 11 20 30 31 40 41 42 43 44 50 51 52 53 59 60 61 62))))
+(define (gemini-error-code? status)
+ (list? (member status '(40 41 42 43 44 50 51 52 53 59 60 61 62))))
+
(define (gemtext->gemexpr str)
(map (lambda (l) (gemini-process-line l)) (string-split str "\n")))
@@ 166,6 174,7 @@
gemini-request
gemini-valid-status-code
ensure-gemini-protocol
+ gemini-error-code?
gemtext->gemexpr)
(provide (struct-out gemini-response))
M transports/gemini-transport.rkt => transports/gemini-transport.rkt +1 -1
@@ 39,7 39,7 @@
(define meta (gemini-response-meta last-response))
(define body (gemini-response-body last-response))
(cond
- [(equal? status 51) (on-error (format "Error: ~a not found" new-url))]
+ [(gemini-error-code? status) (on-error (format "Error loading ~a:~n~n ~a" new-url meta))]
[(not (gemini-valid-status-code status)) (on-error (format "Error: invalid status code: ~a" status))]
[else (on-request-complete new-url
(gemini-response-meta last-response)