|
229 | 229 | symbol))
|
230 | 230 | middleware-list)))
|
231 | 231 |
|
| 232 | +(defn build-aleph-ring-map |
| 233 | + "Constructs an aleph ring map, based on the clj-http ring map. |
| 234 | +
|
| 235 | + Adds corresponding middleware, and copies multipart ByteArrayInputStreams, |
| 236 | + since they can't be read more than once by default." |
| 237 | + [clj-http-ring-map clj-http-middleware] |
| 238 | + (let [middleware-ring-map (merge clj-http-ring-map {:pool (aleph-test-conn-pool clj-http-middleware)})] |
| 239 | + (if (contains? clj-http-ring-map :multipart) |
| 240 | + (update-in middleware-ring-map |
| 241 | + [:multipart] |
| 242 | + (fn [parts] |
| 243 | + (into [] |
| 244 | + (map (fn [part] |
| 245 | + (if (= ByteArrayInputStream (-> part :content class)) |
| 246 | + (let [bais (:content part) |
| 247 | + _ (.mark bais 0) |
| 248 | + aleph-part (assoc part :content (ByteArrayInputStream. (.readAllBytes bais)))] |
| 249 | + (.reset bais) |
| 250 | + aleph-part) |
| 251 | + part))) |
| 252 | + parts))) |
| 253 | + middleware-ring-map))) |
| 254 | + |
232 | 255 | (defn make-request
|
233 | 256 | "Need to switch between clj-http's core/request and client/request.
|
234 | 257 |
|
|
248 | 271 | ;;_ (prn clj-http-ring-map)
|
249 | 272 | clj-http-middleware (if using-middleware? clj-http.client/*current-middleware* [])
|
250 | 273 | ;;_ (print-middleware-list clj-http.client/*current-middleware*)
|
251 |
| - aleph-ring-map (merge base-req req {:pool (aleph-test-conn-pool clj-http-middleware)}) |
| 274 | + aleph-ring-map (build-aleph-ring-map clj-http-ring-map clj-http-middleware) |
252 | 275 | ;;_ (prn aleph-ring-map)
|
253 | 276 | is-multipart (contains? clj-http-ring-map :multipart)
|
254 | 277 | clj-http-resp (clj-http-request clj-http-ring-map)
|
|
280 | 303 | ;;(prn aleph-resp)
|
281 | 304 | ;;(println)
|
282 | 305 |
|
283 |
| - (do |
284 |
| - (println "clj-http req:") |
285 |
| - (prn clj-http-ring-map) |
286 |
| - (println) |
287 |
| - (println "clj-http resp:") |
288 |
| - (prn clj-http-resp) |
289 |
| - (println) |
290 |
| - (println) |
291 |
| - (println "aleph req:") |
292 |
| - (prn aleph-ring-map) |
293 |
| - (println) |
294 |
| - (println "aleph resp:") |
295 |
| - (prn aleph-resp)) |
| 306 | + ;;(do |
| 307 | + ;; (println "clj-http req:") |
| 308 | + ;; (prn clj-http-ring-map) |
| 309 | + ;; (println) |
| 310 | + ;; (println "clj-http resp:") |
| 311 | + ;; (prn clj-http-resp) |
| 312 | + ;; (println) |
| 313 | + ;; (println) |
| 314 | + ;; (println "aleph req:") |
| 315 | + ;; (prn aleph-ring-map) |
| 316 | + ;; (println) |
| 317 | + ;; (println "aleph resp:") |
| 318 | + ;; (prn aleph-resp)) |
296 | 319 |
|
297 | 320 | (is-headers= (apply dissoc (:headers clj-http-resp) multipart-related-headers)
|
298 | 321 | (apply dissoc (:headers aleph-resp) multipart-related-headers))
|
299 | 322 | (assoc clj-http-resp :body (multipart-resp= clj-http-resp aleph-resp)))
|
300 | 323 | (do
|
301 | 324 | (is-headers= (:headers clj-http-resp) (:headers aleph-resp))
|
302 |
| - (let [new-clj-http-body (bodies= (:body clj-http-resp) (:body aleph-resp) is-multipart)] |
| 325 | + (let [new-clj-http-body (bodies= (:body clj-http-resp) (:body aleph-resp))] |
303 | 326 | (assoc clj-http-resp :body new-clj-http-body)))))))))
|
0 commit comments