Reputation: 11057
I'm trying to get up an running using http://github.com/rnewman/clj-apache-http
(http/get (java.net.URI. url)
:headers {"User-Agent" user-agent}
:parameters (http/map->params
{:default-proxy (http/http-host :host "localhost"
:port 8888)})
:as :string)
Problem is, my proxy (squid) requires authentication. How do I "feed" my username/password into this library?
Thanks!
Upvotes: 2
Views: 500
Reputation: 11057
Adding the following to my headers dictionary did the trick:
"Proxy-Authorization" (str "Basic "
(base64/encode-str "username:password"))
Like Mac said -- this could also be implemented with a filter -- but preemptive-basic-auth-filter won't work because it sends the headers for WWW-Authorization instead of Proxy-Authorization.
Upvotes: 2
Reputation: 10075
clj-apache-http has a preemptive-basic-auth-filter that you can use. It supports combined username / password strings of this form "name:password". Use of the function is not well documented but can be found here. Example (not tested):
(http/get (java.net.URI. url)
:headers {"User-Agent" user-agent}
:parameters (http/map->params
{:default-proxy (http/http-host :host "localhost"
:port 8888)})
:as :string
:filters ((preemptive-basic-auth-filter "name:password")))
Upvotes: 0