X Tutup
Skip to content

Allow RequestConfig and HttpClientContext to be injected#375

Merged
dakrone merged 1 commit intodakrone:masterfrom
EvanHahn:override-request-config-and-context
May 24, 2017
Merged

Allow RequestConfig and HttpClientContext to be injected#375
dakrone merged 1 commit intodakrone:masterfrom
EvanHahn:override-request-config-and-context

Conversation

@EvanHahn
Copy link
Contributor

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
@dakrone
Copy link
Owner

dakrone commented May 24, 2017

This looks great, thanks @EvanHahn!

@EvanHahn EvanHahn deleted the override-request-config-and-context branch September 22, 2017 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup