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!

2 Answers 2

2

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.

0

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")))
2
  • 1
    I don't think preemptive-basic-auth-filter will work because it sends the headers for WWW-Authorization instead of Proxy-Authorization.
    – erikcw
    Mar 30, 2010 at 20:57
  • Just in case anyone else ever refers to this, the filters should be a sequence of functions, so it should actually be :filters [(preemptive-basic-auth-filter "name:password")]
    – colinf
    Jul 15, 2011 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.