summaryrefslogtreecommitdiff
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
parent99368091dfa733e0e7823072e79c7d4f03c2b700 (diff)
requests: Parse the result according to content-type
-rw-r--r--neocities/api.scm10
-rw-r--r--neocities/requests.scm13
2 files changed, 14 insertions, 9 deletions
diff --git a/neocities/api.scm b/neocities/api.scm
index fe68ce2..5e3d2d0 100644
--- a/neocities/api.scm
+++ b/neocities/api.scm
@@ -116,8 +116,8 @@
#:hostname (neocities-api-hostname api))))
(let-values (((boundary body) (encode-multipart-body files)))
(neocities-request
- 'POST
- url
- #:content-type (string-append "multipart/form-data; boundary=" boundary)
- #:body body
- #:auth (encode-auth (neocities-api-auth api))))))
+ 'POST
+ url
+ #:content-type (string-append "multipart/form-data; boundary=" boundary)
+ #:body body
+ #:auth (encode-auth (neocities-api-auth api))))))
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)))))