New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow RequestConfig and HttpClientContext to be injected #375

Merged
merged 1 commit into from May 24, 2017

Conversation

Projects
None yet
2 participants
@EvanHahn
Contributor

EvanHahn commented May 17, 2017

This allows the RequestConfig and HttpClientContext instances to be overridden.

It is done like so:

(client/request {:method :get
                 :url "http://localhost:18080/get"
                 :http-client-context my-http-client-context
                 :http-request-config my-request-config})

We thinks this allows for more flexibility. In our case, it helps us do some fancier things with proxies. We want to set an AuthCache on our HttpClientContext instance, which looks something like this:

;; Our code looks like this...
(defn additional-cljhttp-options [proxy-host proxy-port proxy-user proxy-pass]
  (let [host (HttpHost. proxy-host proxy-port "http")
        creds (doto (BasicCredentialsProvider.)
                (.setCredentials AuthScope/ANY (UsernamePasswordCredentials. proxy-user proxy-pass)))
        basic-scheme (doto (BasicScheme.)
                       (.processChallenge (BasicHeader. HttpHeaders/PROXY_AUTHENTICATE "Basic")))
        auth-cache (doto (BasicAuthCache.)
                     (.put host basic-scheme))
        context (doto (HttpClientContext/create)
                  (.setCredentialsProvider creds)
                  (.setAuthCache auth-cache))
        request-config (-> (RequestConfig/custom) (.setProxy host) (.build))]
    {:http-client-context context :http-request-config request-config}))

This seems like it would also help solve #307 and allow SOCKS authentication to be provided, and perhaps help with #225.

Feedback is welcome, especially on some of the naming and spying done in the new test.

@dakrone dakrone merged commit feb3c48 into dakrone:master May 24, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@dakrone

This comment has been minimized.

Show comment
Hide comment
@dakrone

dakrone May 24, 2017

Owner

This looks great, thanks @EvanHahn!

Owner

dakrone commented May 24, 2017

This looks great, thanks @EvanHahn!

@EvanHahn EvanHahn deleted the EvanHahn:override-request-config-and-context branch Sep 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment