diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-11-28 22:12:59 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-11-28 22:12:59 +0100 |
commit | ee2d874119b898114c6f4b61051cc3c35e1bab38 (patch) | |
tree | 9e9b29ff3b14383b05d7212b1f492a3c316f0482 | |
parent | cb17c4422b6ef005556b7b6fdc137580b6f0e89e (diff) | |
download | guile-ee2d874119b898114c6f4b61051cc3c35e1bab38.tar.gz |
web: Export `text-content-type?'.
* module/web/client.scm (text-type?): Remove.
(decode-response-body): Use `text-content-type?'.
* module/web/response.scm (text-content-type?): New procedure.
* doc/ref/web.texi (Responses): Document it.
-rw-r--r-- | doc/ref/web.texi | 6 | ||||
-rw-r--r-- | module/web/client.scm | 8 | ||||
-rw-r--r-- | module/web/response.scm | 9 |
3 files changed, 16 insertions, 7 deletions
diff --git a/doc/ref/web.texi b/doc/ref/web.texi index 3e93beab3..a93072f96 100644 --- a/doc/ref/web.texi +++ b/doc/ref/web.texi @@ -1361,6 +1361,12 @@ headers. Return the given response header, or @var{default} if none was present. @end deffn +@deffn {Scheme Procedure} text-content-type? @var{type} +Return @code{#t} if @var{type}, a symbol as returned by +@code{response-content-type}, represents a textual type such as +@code{text/plain}. +@end deffn + @node Web Client @subsection Web Client diff --git a/module/web/client.scm b/module/web/client.scm index 66f25630c..d9dff0322 100644 --- a/module/web/client.scm +++ b/module/web/client.scm @@ -83,12 +83,6 @@ (close-port p) res)))) -(define (text-type? type) - (let ((type (symbol->string type))) - (or (string-prefix? "text/" type) - (string-suffix? "/xml" type) - (string-suffix? "+xml" type)))) - ;; Logically the inverse of (web server)'s `sanitize-response'. ;; (define (decode-response-body response body) @@ -104,7 +98,7 @@ ((response-content-type response) => (lambda (type) (cond - ((text-type? (car type)) + ((text-content-type? (car type)) (decode-string body (or (assq-ref (cdr type) 'charset) "iso-8859-1"))) (else body)))) diff --git a/module/web/response.scm b/module/web/response.scm index aaa770792..46345c0fd 100644 --- a/module/web/response.scm +++ b/module/web/response.scm @@ -62,6 +62,7 @@ response-content-md5 response-content-range response-content-type + text-content-type? response-expires response-last-modified @@ -175,6 +176,14 @@ reason phrase for the response's code." (or (%response-reason-phrase response) (code->reason-phrase (response-code response)))) +(define (text-content-type? type) + "Return #t if TYPE, a symbol as returned by `response-content-type', +represents a textual type such as `text/plain'." + (let ((type (symbol->string type))) + (or (string-prefix? "text/" type) + (string-suffix? "/xml" type) + (string-suffix? "+xml" type)))) + (define (read-response port) "Read an HTTP response from PORT. |