diff options
author | Mike Gran <spk121@yahoo.com> | 2021-03-11 19:42:33 -0800 |
---|---|---|
committer | Mike Gran <spk121@yahoo.com> | 2021-03-11 19:42:33 -0800 |
commit | 0f983e3db0c43ad7c89f57ea84f792ede373ba0c (patch) | |
tree | a56172dd2fac12e2ba9d9eeafeabfd3ea95cad56 /module/web/http.scm | |
parent | a744f98dcc294ab2cbe1cb5ce4efa66665f4e03f (diff) | |
download | guile-0f983e3db0c43ad7c89f57ea84f792ede373ba0c.tar.gz |
Handle CRLF and Unicode line endings in read-line
* libguile/rdelim.c (scm_read_line): handle CRLF, LS and PS
* module/ice-9/suspendable-ports.scm (read-line): handle CRLF, LS, and PS
* module/web/http.scm (read-header-line): take advantage of CRLF in read-line
(read-header): don't need to test for \return
* test-suite/tests/rdelim.test: new tests for read-line CRLF, LS and PS
* doc/ref/api-io.texi: update doc for read-line
Diffstat (limited to 'module/web/http.scm')
-rw-r--r-- | module/web/http.scm | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/module/web/http.scm b/module/web/http.scm index 4276e1744..32a3093f1 100644 --- a/module/web/http.scm +++ b/module/web/http.scm @@ -157,13 +157,12 @@ The default writer will call ‘put-string’." Raise a 'bad-header' exception if the line does not end in CRLF or LF, or if EOF is reached." (match (%read-line port) + (((? string? line) . "\r\n") + line) (((? string? line) . #\newline) - ;; '%read-line' does not consider #\return a delimiter; so if it's - ;; there, remove it. We are more tolerant than the RFC in that we - ;; tolerate LF-only endings. - (if (string-suffix? "\r" line) - (string-drop-right line 1) - line)) + ;; We are more tolerant than the RFC in that we tolerate LF-only + ;; endings. + line) ((line . _) ;EOF or missing delimiter (bad-header 'read-header-line line)))) @@ -184,8 +183,7 @@ was known but the value was invalid. Returns the end-of-file object for both values if the end of the message body was reached (i.e., a blank line)." (let ((line (read-header-line port))) - (if (or (string-null? line) - (string=? line "\r")) + (if (string-null? line) (values *eof* *eof*) (let* ((delim (or (string-index line #\:) (bad-header '%read line))) |