views:

33

answers:

2

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!

A: 

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")))
mac
I don't think preemptive-basic-auth-filter will work because it sends the headers for WWW-Authorization instead of Proxy-Authorization.
erikcw
+1  A: 

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.

erikcw