Skip to content

Commit

Permalink
Merge branch 'pr/650' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Aug 19, 2024
2 parents 37d9062 + ab34134 commit a9262a6
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/clj_http/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
(:import [java.io BufferedReader ByteArrayInputStream ByteArrayOutputStream EOFException File InputStream]
[java.net UnknownHostException URL]
[org.apache.http.entity BufferedHttpEntity ByteArrayEntity FileEntity InputStreamEntity StringEntity]
[javax.xml.parsers SAXParserFactory]
[javax.xml.parsers SAXParser SAXParserFactory]
org.xml.sax.helpers.DefaultHandler
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager))

Expand Down Expand Up @@ -474,18 +475,25 @@
(util/force-string body charset))]
(assoc resp :body body)))

(defn- sax-parser ^SAXParser []
(..
(doto
(SAXParserFactory/newInstance)
(.setFeature
"http://apache.org/xml/features/nonvalidating/load-external-dtd" false))
(newSAXParser)))

(defn- non-validating [s ^DefaultHandler ch]
(let [parser (sax-parser)]
(cond
(instance? String s) (.parse parser ^String s ch)
(instance? InputStream s) (.parse parser ^InputStream s ch)
:else (throw (ex-info "Unsupported input" {:s s})))))

(defn- decode-xml-body [body]
(let [non-validating (fn [s ch]
(..
(doto
(SAXParserFactory/newInstance)
(.setFeature
"http://apache.org/xml/features/nonvalidating/load-external-dtd" false))
(newSAXParser)
(parse s ch)))]
(-> body
(util/force-stream)
(xml/parse non-validating))))
(-> body
(util/force-stream)
(xml/parse non-validating)))

(defn coerce-xml-body
[request {:keys [body] :as resp} & [charset]]
Expand Down Expand Up @@ -892,7 +900,6 @@
([req respond raise]
(client (oauth-request req) respond raise))))


(defn parse-user-info [user-info]
(when user-info
(str/split user-info #":")))
Expand Down

0 comments on commit a9262a6

Please sign in to comment.