summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ref/web.texi6
-rw-r--r--module/web/client.scm8
-rw-r--r--module/web/response.scm9
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.