separate page request, extract strings to separate file (localization?)
This commit is contained in:
parent
6dda3a8f16
commit
6e37ad0396
58
rebound.rkt
58
rebound.rkt
|
@ -1,60 +1,8 @@
|
|||
#lang racket/gui
|
||||
(require openssl)
|
||||
(require "request-page.rkt")
|
||||
|
||||
(define port 1965)
|
||||
(define target "geminiprotocol.net")
|
||||
(define request "gemini://geminiprotocol.net/index.gmi\r\n")
|
||||
(define request "gemini://geminiprotocol.net/\r\n")
|
||||
|
||||
(define-values (in out) (ssl-connect/enable-break target port))
|
||||
(file-stream-buffer-mode out 'none)
|
||||
|
||||
(display request out)
|
||||
(flush-output out)
|
||||
|
||||
(let* ([response-head (read-line in)]
|
||||
[status (string->number (substring response-head 0 2))]
|
||||
[status-first (quotient status 10)]
|
||||
[status-last (modulo status 10)]
|
||||
[info (if (> (string-length response-head) 2)
|
||||
(string-trim (substring response-head 2))
|
||||
"[none given]")])
|
||||
(case status-first
|
||||
[(1) (case status-last
|
||||
[(1) (display "requesting sensitive input, ")]
|
||||
[else (display "requesting normal input, ")])
|
||||
(displayln (~a "input prompt: " info))]
|
||||
|
||||
[(2) (case info
|
||||
[("text/gemini" "text/plain") (displayln (port->string in))]
|
||||
[else (displayln (~a "requested file is of unhandled mimetype: " info))])]
|
||||
|
||||
[(3) (case status-last
|
||||
[(1) (display "permanently")]
|
||||
[else (display "temporarily")])
|
||||
(displayln (~a " redirecting to: " info))]
|
||||
|
||||
[(4) (display "temporary failure, reason: ")
|
||||
(case status-last
|
||||
[(1) (display "server unavailable")]
|
||||
[(2) (display "cgi error")]
|
||||
[(3) (display "proxy error")]
|
||||
[(4) (display "SLOW DOWN")]
|
||||
[else (display "unspecified")])
|
||||
(displayln (~a "; error message: " info))]
|
||||
|
||||
[(5) (display "permanent failure, reason: ")
|
||||
(case status-last
|
||||
[(1) (display "file not found")]
|
||||
[(2) (display "gone")]
|
||||
[(3) (display "proxy request refused")]
|
||||
[(9) (display "bad request")]
|
||||
[else (display "unspecified")])
|
||||
(displayln (~a "; error message: " info))]
|
||||
|
||||
[(6) (display "client certificate ")
|
||||
(case status-last
|
||||
[(1) (display "not authorized")]
|
||||
[(2) (display "not valid")]
|
||||
[else (display "required")])
|
||||
(displayln (~a "; error message: " info))]
|
||||
))
|
||||
(displayln (request-uri target port request))
|
||||
|
|
52
request-page.rkt
Normal file
52
request-page.rkt
Normal file
|
@ -0,0 +1,52 @@
|
|||
#lang racket/gui
|
||||
(require openssl)
|
||||
(require "strings.rkt")
|
||||
(provide request-uri)
|
||||
|
||||
(define (request-uri target port request)
|
||||
(let-values ([(in out) (ssl-connect/enable-break target port)])
|
||||
(file-stream-buffer-mode out 'none)
|
||||
(display request out)
|
||||
(flush-output out)
|
||||
|
||||
(let* (
|
||||
[response-head (read-line in)]
|
||||
[status (string->number (substring response-head 0 2))]
|
||||
[status-first (quotient status 10)]
|
||||
[status-last (modulo status 10)]
|
||||
[info (if (> (string-length response-head) 2)
|
||||
(string-trim (substring response-head 2))
|
||||
none-given)])
|
||||
(case status-first
|
||||
[(1) (case status-last
|
||||
[(1) (~a sensitive-input info)]
|
||||
[else (~a normal-input info)])]
|
||||
|
||||
[(2) (case info
|
||||
[("text/gemini" "text/plain")
|
||||
(port->string in)]
|
||||
[else (~a unhandled-mimetype info)])]
|
||||
|
||||
[(3) (case status-last
|
||||
[(1) (~a permanently-redirecting info)]
|
||||
[else (~a temporarily-redirecting info)])]
|
||||
|
||||
[(4) (case status-last
|
||||
[(1) (~a server-unavailable info)]
|
||||
[(2) (~a cgi-error info)]
|
||||
[(3) (~a proxy-error info)]
|
||||
[(4) (~a slow-down info)]
|
||||
[else (~a temporary-unspecified info)])]
|
||||
|
||||
[(5) (case status-last
|
||||
[(1) (~a file-not-found info)]
|
||||
[(2) (~a file-gone info)]
|
||||
[(3) (~a proxy-refused info)]
|
||||
[(9) (~a bad-request info)]
|
||||
[else (~a permanent-unspecified info)])]
|
||||
|
||||
[(6) (case status-last
|
||||
[(1) (~a cert-unauthorized info)]
|
||||
[(2) (~a cert-invalid info)]
|
||||
[else (~a cert-required info)])]
|
||||
[else (~a bad-status status)]))))
|
27
strings.rkt
Normal file
27
strings.rkt
Normal file
|
@ -0,0 +1,27 @@
|
|||
#lang racket/gui
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define none-given "[none given]")
|
||||
|
||||
(define error-message "; error message: ")
|
||||
(define prompt "; prompt: ")
|
||||
|
||||
(define sensitive-input (~a "sensitive input requested" prompt))
|
||||
(define normal-input (~a "normal input requested" prompt))
|
||||
(define unhandled-mimetype "requested file is of unhandled mimetype: ")
|
||||
(define permanently-redirecting "permanently redirecting to: ")
|
||||
(define temporarily-redirecting "temporarily redirecting to: ")
|
||||
(define server-unavailable (~a "server unavailable" error-message))
|
||||
(define cgi-error (~a "cgi error" error-message))
|
||||
(define proxy-error (~a "proxy error" error-message))
|
||||
(define slow-down (~a "SLOW DOWN" error-message))
|
||||
(define temporary-unspecified (~a "unspecified temporary error" error-message))
|
||||
(define file-not-found (~a "file not found" error-message))
|
||||
(define file-gone (~a "file gone" error-message))
|
||||
(define proxy-refused (~a "proxy request refused" error-message))
|
||||
(define bad-request (~a "bad request" error-message))
|
||||
(define permanent-unspecified (~a "unspecified permanent error" error-message))
|
||||
(define cert-unauthorized (~a "client certificate not authorized" error-message))
|
||||
(define cert-invalid (~a "client certificate not valid" error-message))
|
||||
(define cert-required (~a "client certificate required" error-message))
|
||||
(define bad-status "bad status code served: ")
|
Loading…
Reference in a new issue