clj-commons / aleph

Asynchronous streaming communication for Clojure - web server, web client, and raw TCP/UDP
http://aleph.io
MIT License
2.54k stars 241 forks source link

:follow-redirects? does not follow through #597

Closed jetmind closed 2 years ago

jetmind commented 2 years ago
› cat deps.edn 
{:deps {aleph/aleph {:mvn/version "0.4.7"}}}

› clj
Clojure 1.10.3
user=> (require '[aleph.http :as http])
nil
user=> (-> (http/request {:method :get :url "http://httpbin.org/status/301" :follow-redirects? true}) deref :status)
301

expected status 200

jetmind commented 2 years ago

Ok, I shoud have used :request-method instead of :method. Everything works.

KingMob commented 2 years ago

Hmmm, not so fast. There's the aleph.http.client-middleware/wrap-method in the default middleware that should fix this exact issue.

KingMob commented 2 years ago

There's also a discrepancy in the keywords/docs between follow-redirects? and follow-redirects

EDIT: nm, I forgot there's a fn that checks the option with or without the ?

KingMob commented 2 years ago

The issue is that the chained fn that handles the response, reuses the original request map for some things, namely cookies and the request method, from before the request middleware was applied. After a close reading, I don't think the cookie code is impacted, but this explains why wrap-method didn't fix it.