summaryrefslogtreecommitdiff
path: root/neocities/requests.scm
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2023-09-29 12:13:38 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2023-09-30 16:16:02 +0200
commit20a6598147a3cba39edf3a5c63ba059814fa5aab (patch)
tree00051dec6df1cd97ac8202ecb25cece8865ad7ef /neocities/requests.scm
parent99368091dfa733e0e7823072e79c7d4f03c2b700 (diff)
requests: Parse the result according to content-type
Diffstat (limited to 'neocities/requests.scm')
-rw-r--r--neocities/requests.scm13
1 files changed, 9 insertions, 4 deletions
diff --git a/neocities/requests.scm b/neocities/requests.scm
index 56979c4..094b7bf 100644
--- a/neocities/requests.scm
+++ b/neocities/requests.scm
@@ -25,14 +25,13 @@
(define-module (neocities requests)
#:use-module (neocities mime)
- #:use-module (json)
#:use-module (ice-9 match)
#:use-module (ice-9 iconv)
#:use-module (ice-9 binary-ports)
+ #:use-module (json)
#:use-module (gcrypt base64)
#:use-module (gcrypt random)
#:use-module (rnrs base)
- #:use-module (rnrs bytevectors)
#:use-module (scheme base)
#:use-module (web uri)
#:use-module (web client)
@@ -151,7 +150,13 @@
(list
(and content-type `(Content-Type . ,content-type))
(and auth `(Authorization . ,auth))))
- #:decode-body? #t)))
+ #:decode-body? #f)))
(if (response-ok? response)
- (json-string->scm (utf8->string body))
+ (match (response-content-type response)
+ (('text/plain ('charset . "utf-8"))
+ (utf8->string body))
+ (('application/json . rest)
+ (json-string->scm (utf8->string body)))
+ (else
+ (throw 'neocities "Don't know how to decode "(response-content-type response))))
(throw 'neocities (response-error response)))))