diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2021-02-25 15:17:18 +0100 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2021-02-25 15:20:43 +0100 |
commit | d78fe77f32a6ea0a81632e61a6461beb0d45a73a (patch) | |
tree | 61e64b2e57e02184e17ec1cd8a00cad0a14b3a9d | |
parent | 83e1bb5afeb0205b8b8ef07df6be16f3c68e7cf3 (diff) |
request: Parse JSON responses.
* aws/request.scm (make-operation->request): Inspect content-type of
server response.
-rw-r--r-- | aws/request.scm | 16 | ||||
-rw-r--r-- | configure.ac | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/aws/request.scm b/aws/request.scm index d311ec2..7ccb6c6 100644 --- a/aws/request.scm +++ b/aws/request.scm @@ -26,8 +26,10 @@ #:use-module (gcrypt hmac) #:use-module (rnrs bytevectors) #:use-module (web client) + #:use-module ((web response) #:select (response-content-type)) #:use-module ((web http) #:select (header-writer declare-header!)) #:use-module (sxml simple) + #:use-module (json) #:export (make-operation->request serialize-aws-value)) ;;; Commentary: @@ -264,7 +266,13 @@ (_ "")) #:headers new-headers)) (lambda (response body) - (xml->sxml (match body - ((? bytevector? bv) - (utf8->string bv)) - ((? string? s) s))))))) + (let ((server-text (match body + ((? bytevector? bv) + (utf8->string bv)) + ((? string? s) s)))) + (match (response-content-type response) + (('application/x-amz-json-1.1 . rest) + (json-string->scm server-text)) + (('text/xml . rest) + (xml->sxml server-text)) + (_ server-text))))))) diff --git a/configure.ac b/configure.ac index 0b86834..24ac639 100644 --- a/configure.ac +++ b/configure.ac @@ -11,5 +11,6 @@ AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env]) GUILE_PKG([3.0 2.2]) GUILE_PROGS +GUILE_MODULE_REQUIRED(json) AC_OUTPUT |