|
321 | 321 | (clojure.pprint/pprint (bean http-req))) |
322 | 322 |
|
323 | 323 | (defn- build-response-map |
324 | | - [^HttpResponse response req conn-mgr ^HttpClientContext context] |
| 324 | + [^HttpResponse response req ^HttpUriRequest http-req |
| 325 | + conn-mgr ^HttpClientContext context] |
325 | 326 | (let [^HttpEntity entity (.getEntity response) |
326 | 327 | status (.getStatusLine response) |
327 | | - protocol-version (.getProtocolVersion status)] |
328 | | - {:body (coerce-body-entity entity conn-mgr response) |
329 | | - :headers (parse-headers |
330 | | - (.headerIterator response) |
331 | | - (opt req :use-header-maps-in-response)) |
332 | | - :length (if (nil? entity) 0 (.getContentLength entity)) |
333 | | - :chunked? (if (nil? entity) false (.isChunked entity)) |
334 | | - :repeatable? (if (nil? entity) false (.isRepeatable entity)) |
335 | | - :streaming? (if (nil? entity) false (.isStreaming entity)) |
336 | | - :status (.getStatusCode status) |
337 | | - :protocol-version {:name (.getProtocol protocol-version) |
338 | | - :major (.getMajor protocol-version) |
339 | | - :minor (.getMinor protocol-version)} |
340 | | - :reason-phrase (.getReasonPhrase status) |
341 | | - :trace-redirects (mapv str (.getRedirectLocations context))})) |
| 328 | + protocol-version (.getProtocolVersion status) |
| 329 | + body (:body req) |
| 330 | + response |
| 331 | + {:body (coerce-body-entity entity conn-mgr response) |
| 332 | + :headers (parse-headers |
| 333 | + (.headerIterator response) |
| 334 | + (opt req :use-header-maps-in-response)) |
| 335 | + :length (if (nil? entity) 0 (.getContentLength entity)) |
| 336 | + :chunked? (if (nil? entity) false (.isChunked entity)) |
| 337 | + :repeatable? (if (nil? entity) false (.isRepeatable entity)) |
| 338 | + :streaming? (if (nil? entity) false (.isStreaming entity)) |
| 339 | + :status (.getStatusCode status) |
| 340 | + :protocol-version {:name (.getProtocol protocol-version) |
| 341 | + :major (.getMajor protocol-version) |
| 342 | + :minor (.getMinor protocol-version)} |
| 343 | + :reason-phrase (.getReasonPhrase status) |
| 344 | + :trace-redirects (mapv str (.getRedirectLocations context))}] |
| 345 | + (if (opt req :save-request) |
| 346 | + (-> response |
| 347 | + (assoc :request req) |
| 348 | + (assoc-in [:request :body-type] (type body)) |
| 349 | + (update-in [:request] |
| 350 | + #(if (opt req :debug-body) |
| 351 | + (assoc % :body-content |
| 352 | + (cond |
| 353 | + (isa? (type (:body %)) String) |
| 354 | + (:body %) |
| 355 | + |
| 356 | + (isa? (type (:body %)) HttpEntity) |
| 357 | + (let [baos (ByteArrayOutputStream.)] |
| 358 | + (.writeTo ^HttpEntity (:body %) baos) |
| 359 | + (.toString baos "UTF-8")) |
| 360 | + |
| 361 | + :else nil)) |
| 362 | + %)) |
| 363 | + (assoc-in [:request :http-req] http-req)) |
| 364 | + response))) |
342 | 365 |
|
343 | 366 | (defn- get-conn-mgr |
344 | 367 | [async? req] |
|
418 | 441 | client (http-client req conn-mgr http-url proxy-ignore-hosts)] |
419 | 442 | (try |
420 | 443 | (build-response-map (.execute client http-req context) |
421 | | - req conn-mgr context) |
| 444 | + req http-req conn-mgr context) |
422 | 445 | (catch Throwable t |
423 | 446 | (when-not (conn/reusable? conn-mgr) |
424 | 447 | (conn/shutdown-manager conn-mgr)) |
|
437 | 460 | (completed [this resp] |
438 | 461 | (try |
439 | 462 | (respond (build-response-map |
440 | | - resp req conn-mgr context)) |
| 463 | + resp req http-req conn-mgr context)) |
441 | 464 | (catch Throwable t |
442 | 465 | (when-not (conn/reusable? conn-mgr) |
443 | 466 | (conn/shutdown-manager conn-mgr)) |
|
0 commit comments