doto and setting property conditionally
I want to write:

    (defn download-web-page
        "Downloads the webpage at the given url and returns its contents."
        [^String url ^String user ^String password]
        (with-open [client (doto (WebClient.)
                           (when user (.set_Credentials (NetworkCredential. user password ""))))]
        (.DownloadString client url)))

So I want to set the credentials only when they are given as an argument to the function. However it doesn't seem to work that way - and neither does it when I replace the when with an if.

The function works fine if I remove the when altogether.

I guess I can't use a when in a doto - are there nice ways to write this?
doto and setting property conditionally
===

I want to write:

    (defn download-web-page
        "Downloads the webpage at the given url and returns its contents."
        [^String url ^String user ^String password]
        (with-open [client (doto (WebClient.)
                           (when user (.set_Credentials (NetworkCredential. user password ""))))]
        (.DownloadString client url)))

So I want to set the credentials only when they are given as an argument to the function. However it doesn't seem to work that way - and neither does it when I replace the when with an if.

The function works fine if I remove the when altogether.

I guess I can't use a when in a doto - are there nice ways to write this?