(TK-27) Dry up use of defaults

Dry up use of defaults. Now, the second signature of the
request function will pass in nil for the client argument
in the third signature, which will create a default client if no
client was provided.
This commit is contained in:
Preben Ingvaldsen 2014-07-17 11:39:35 -07:00
parent 81cd0eabaf
commit d7e283df42
2 changed files with 10 additions and 18 deletions

View file

@ -228,14 +228,8 @@
(select-keys opts [:ssl-context :ssl-ca-cert :ssl-cert :ssl-key]))
(schema/defn create-default-client :- common/Client
[opts :- common/RawUserRequestOptions]
(let [defaults {:headers {}
:body nil
:decompress-body true
:as :stream}
opts (merge defaults opts)
client-opts (extract-client-opts opts)
configured-opts (configure-ssl client-opts)
[opts :- common/ClientOptions]
(let [configured-opts (configure-ssl opts)
client (if (:ssl-context configured-opts)
(.. (HttpAsyncClients/custom) (setSSLContext (:ssl-context configured-opts)) build)
(HttpAsyncClients/createDefault))]
@ -279,18 +273,18 @@
(request opts nil))
([opts :- common/RawUserRequestOptions
callback :- common/ResponseCallbackFn]
(let [client (create-default-client opts)
opts (assoc opts :persistent false)]
(request opts callback client)))
(request opts callback nil))
([opts :- common/RawUserRequestOptions
callback :- common/ResponseCallbackFn
client :- common/Client]
(let [defaults {:headers {}
client]
(let [persistent (not (nil? client))
defaults {:headers {}
:body nil
:decompress-body true
:as :stream
:persistent true}
opts (merge defaults opts)
:as :stream}
opts (assoc (merge defaults opts) :persistent persistent)
client-opts (extract-client-opts opts)
client (or client (create-default-client client-opts))
{:keys [method url body] :as coerced-opts} (coerce-opts opts)
request (construct-request method url)
result (promise)]

View file

@ -48,8 +48,6 @@
(ok :body) Body
(ok :decompress-body) schema/Bool
(ok :as) BodyType
(schema/optional-key
:persistent) schema/Bool
(ok :ssl-context) SSLContext
(ok :ssl-cert) UrlOrString