diff options
-rw-r--r-- | neocities/api.scm | 10 | ||||
-rw-r--r-- | neocities/requests.scm | 13 |
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))))) |