|
75 | 75 | :status status |
76 | 76 | :body body-str))) |
77 | 77 |
|
78 | | -(defun parse-response (response body-type wrapper-name error-map) |
| 78 | +(defun parse-response (response body-type wrapper-name error-map &optional default-content-type) |
79 | 79 | (destructuring-bind (body status headers &rest ignore-args) |
80 | 80 | response |
| 81 | + ;; TODO: Parse also from headers |
81 | 82 | (declare (ignore ignore-args)) |
82 | | - (let ((content-type (gethash "content-type" headers))) |
| 83 | + (let ((content-type (or (gethash "content-type" headers) |
| 84 | + default-content-type))) |
83 | 85 | (if (<= 400 status 599) |
84 | 86 | (parse-response-error body status content-type error-map) |
85 | | - (if (equal body-type "blob") |
86 | | - body |
87 | | - (let ((body-str (ensure-string (or body "")))) |
88 | | - (cond |
89 | | - ((or (string-prefix-p "text/xml" content-type) |
90 | | - (string-prefix-p "application/xml" content-type)) |
91 | | - (let* ((output (xmls-to-alist (xmls:parse-to-list body-str))) |
92 | | - (output ;; Unwrap the root element |
93 | | - (cdr (first output)))) |
94 | | - (if wrapper-name |
95 | | - (values (aget output wrapper-name) |
96 | | - (aget output "ResponseMetadata")) |
97 | | - output))) |
98 | | - ((member content-type '("application/json" "application/x-amz-json-1.1" "application/x-amz-json-1.0") |
99 | | - :test #'string=) |
100 | | - (yason:parse body-str :object-as :alist)) |
101 | | - (t |
102 | | - body-str)))))))) |
| 87 | + (values |
| 88 | + (if (equal body-type "blob") |
| 89 | + body |
| 90 | + (let ((body-str (ensure-string (or body "")))) |
| 91 | + (cond |
| 92 | + ((or (string-prefix-p "text/xml" content-type) |
| 93 | + (string-prefix-p "application/xml" content-type)) |
| 94 | + (let* ((output (xmls-to-alist (xmls:parse-to-list body-str))) |
| 95 | + (output ;; Unwrap the root element |
| 96 | + (cdr (first output)))) |
| 97 | + (if wrapper-name |
| 98 | + (values (aget output wrapper-name) |
| 99 | + (aget output "ResponseMetadata")) |
| 100 | + output))) |
| 101 | + ((member content-type '("application/json" "application/x-amz-json-1.1" "application/x-amz-json-1.0") |
| 102 | + :test #'string=) |
| 103 | + (yason:parse body-str :object-as :alist)) |
| 104 | + (t |
| 105 | + body-str)))) |
| 106 | + status |
| 107 | + headers))))) |
103 | 108 |
|
104 | 109 | (defun compile-path-pattern (path-pattern) |
105 | 110 | (when path-pattern |
|
121 | 126 | ,@slots)) |
122 | 127 | path-pattern)))) |
123 | 128 |
|
124 | | -(defun compile-operation (service name options params body-type error-map) |
| 129 | +(defun compile-operation (service name options params body-type error-map protocol) |
125 | 130 | (let* ((output (gethash "output" options)) |
126 | 131 | (method (gethash "method" (gethash "http" options))) |
127 | 132 | (request-uri (gethash "requestUri" (gethash "http" options)))) |
|
141 | 146 | ,body-type |
142 | 147 | ,(and output |
143 | 148 | (gethash "resultWrapper" output)) |
144 | | - ,error-map))) |
| 149 | + ,error-map |
| 150 | + ,(case protocol |
| 151 | + ((:json :rest-json) "application/json") |
| 152 | + (:rest-xml "application/xml"))))) |
145 | 153 | (export ',(lispify name)))) |
146 | 154 | `(progn |
147 | 155 | (defun ,(lispify name) () |
|
0 commit comments