From: Tim Vaughan Date: Sun, 5 May 2019 22:27:30 +0000 (+0200) Subject: Support for broken url handling in clients. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scratchy.git;a=commitdiff_plain;h=d7925f64bd746c0cdb935654a335a9c8443dd422 Support for broken url handling in clients. Some clients (looking at you, Lynx) actually try to treat the directory entry for http links as a gopher link instead of going straight to the provided url. This update adds a text response that instructs users of these clients on what to do in this situation. --- diff --git a/burrower.scm b/burrower.scm index a042e58..4d00253 100644 --- a/burrower.scm +++ b/burrower.scm @@ -68,12 +68,22 @@ ;;; Selector type inference -(define (has-suffix? selector . suffixes) - (if (null? suffixes) +(define (true-for-one? predicate values) + (if (null? values) #f - (if (string-suffix? (car suffixes) selector) + (if (predicate (car values)) #t - (apply has-suffix? selector (cdr suffixes))))) + (true-for-one? predicate (cdr values))))) + +(define (has-suffix? selector . suffixes) + (true-for-one? (lambda (suffix) + (string-suffix? suffix selector)) + suffixes)) + +(define (has-prefix? selector . prefixes) + (true-for-one? (lambda (prefix) + (string-prefix? prefix selector)) + prefixes)) (define (infer-selector-type selector) (let ((l (string-downcase selector))) @@ -82,6 +92,7 @@ ((has-suffix? l ".txt" ".org" ".md") 0) ((has-suffix? l ".png" ".jpg" ".gif" ".bmp" ".tif" ".tga") 'I) ((has-suffix? l "?.scm") 7) + ((has-prefix? l "url:" "/url:") 'h) (else 9)))) @@ -95,6 +106,7 @@ ((1) (serve-directory selector config)) ((0) (serve-text-file selector config)) ((7) (serve-query selector arguments config)) + ((h) (serve-url selector config)) (else (serve-binary-file selector config))))) (define (serve-directory selector config) @@ -157,6 +169,17 @@ (error "Invalid query." selector arguments)))) +(define (serve-url selector config) + (let ((url (substring selector 4))) + (print + "If you are seeing this page, your gopher browser does not\r\n" + "properly support URL directory entries or cannot follow such\r\n" + "links. To view the link you requested, use a web browser to\r\n" + "open the follwing url:\r\n" + "\r\n" + url "\r\n"))) + + ;;; Index rendering (define (serve-info-records string)