Now, let's try to fix board indexes, board lists, and new thread creation.
All HTTP bodies are now represented using bytevectors, not strings. Fix:
--- a/deps/server.scm
+++ b/deps/server.scm
@@ -287,10 +285,10 @@ Initializes our web server.
;;; reads the string content at the given file path:
(define (read-file filename)
- (call-with-input-file filename
- (lambda (port)
- (read-string (char-set) port))))
-
+ (string->utf8
+ (call-with-input-file filename
+ (lambda (port)
+ (read-string (char-set) port)))))
(alternative fix: open file using open-binary-input-file
, read file using call-with-port
and read-bytevector
)
and also:
--- a/bbs.scm
+++ b/bbs.scm
@@ -79,7 +79,7 @@
;(pp (http-header 'host headers #f))
(cond ((equal? method "GET")
(match path
- (() () '(200 () "site root"))
+ (() () `(200 () ,(string->utf8 "site root")))
((,board) () (view-index board))
((,board "list") () (view-list board))
((,board "preferences") () (set-preferences board query-string))
@@ -102,11 +102,11 @@
;;; errors
(define bad-request
- `(400 () "Bad Request"))
+ `(400 () ,(string->utf8 "Bad Request")))
(define not-found
- `(404 () "Not found"))
+ `(404 () ,(string->utf8 "Not found")))
(define method-not-allowed
- '(405 () "Method not allowed"))
+ `(405 () ,(string->utf8 "Method not allowed")))
(define (title board)
(string-append "/" board "/ - SchemeBBS"))
@@ -215,7 +215,7 @@
(let* ((t (call-with-input-file path read))
(posts (lookup-def 'posts t))
(post-number (+ 1 (car (last posts))))
- (body (http-request-body req))
+ (body (utf8->string (http-request-body req)))
(params (parameters->alist body))
(frontpage (lookup-def 'frontpage params))
(message (decode-formdata (lookup-def 'epistula params)))
@@ -252,11 +252,11 @@
(if newthread?
(add-query-string (string-append "/" board) query-string)
(string-append (add-query-string (string-append "/" board) query-string) "#t" thread "p" post))))
- "That was SICP quality!")
+ ,(string->utf8 "That was SICP quality!"))
`(303 ,(list (make-http-header
'location
(string-append (add-query-string (string-append "/" board "/" thread) query-string) "#t" thread "p" post)))
- "That was SICP quality")))
+ ,(string->utf8 "That was SICP quality"))))
(define (update-post-count board thread date post-count)
(let ((cache (make-path *html* board "list")))
@@ -316,7 +316,7 @@
(threads (if (file-exists? list-path)
(call-with-input-file list-path read)
'()))
- (body (http-request-body req))
+ (body (utf8->string (http-request-body req)))
(params (parameters->alist body))
(message (decode-formdata (lookup-def 'epistula params)))
(headline (decode-formdata (lookup-def 'titulus params)))
Then, to make redirections work correctly when creating new threads and messages, we need to add this fix to the beginning of bbs.scm: https://textboard.org/prog/140/88
SchemeBBS now works on MIT Scheme 11.2!
There's one problem left: multi-byte characters. If you try to submit "一二三" through the textarea, you will get something like "ä¸äºä¸". Not sure how to fix this.