mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
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.
This commit is contained in:
parent
cb17c4422b
commit
ee2d874119
3 changed files with 16 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue