|
|
@@ -93,17 +93,24 @@ is replaced with replacement."
|
|
|
|
|
|
;; XML processing
|
|
|
(defun xml-request (url)
|
|
|
- (multiple-value-bind (stream status headers uri http-stream)
|
|
|
+ (multiple-value-bind (raw-body status headers uri http-stream)
|
|
|
(drakma:http-request (http-default url)
|
|
|
- :want-stream t
|
|
|
+ :force-binary t
|
|
|
:decode-content t)
|
|
|
- (declare (ignore status headers))
|
|
|
- (unwind-protect
|
|
|
- (progn
|
|
|
- (when (eq (flex:flexi-stream-element-type stream) 'octet)
|
|
|
- (setf (flex:flexi-stream-external-format stream) :utf-8))
|
|
|
- (values (plump:parse stream) uri))
|
|
|
- (ignore-errors (close http-stream)))))
|
|
|
+ (declare (ignore status headers http-stream))
|
|
|
+ (let* ((dom
|
|
|
+ (handler-case
|
|
|
+ (plump:parse (flex:octets-to-string raw-body :external-format :utf-8))
|
|
|
+ (flex:external-format-encoding-error ()
|
|
|
+ (plump:parse (flex:octets-to-string raw-body)))))
|
|
|
+ (encoding (plump:get-attribute (plump:first-child dom) "encoding")))
|
|
|
+ (values
|
|
|
+ (if (and encoding (not (equal encoding "utf-8")))
|
|
|
+ (plump:parse (flex:octets-to-string
|
|
|
+ raw-body
|
|
|
+ :external-format (intern encoding 'keyword)))
|
|
|
+ dom)
|
|
|
+ uri))))
|
|
|
|
|
|
(defun get-by-tag (node tag)
|
|
|
(nreverse (plump::get-elements-by-tag-name node tag)))
|