Question

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!

No correct solution

OTHER TIPS

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.

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")))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top