studio-b12 / gowebdav

A golang WebDAV client library and command line tool.
BSD 3-Clause "New" or "Revised" License
309 stars 89 forks source link

Creating NewClient with Proxy #56

Closed hrncacz closed 2 years ago

hrncacz commented 2 years ago

Hello,

I have used this module in one of my projects and I was missing functionality for defining proxy server directly from program. In my case I am not able to use env variables HTTP/HTTPS_PROXY. This new function NewClientProxy() solves that issue.

chripo commented 2 years ago

thank you for your suggestions.

i my opinion this code should be kept outside of this project to favor separation of concerns. the library cares about the protocol and less about the transport. on top it`s a more flexible and cleaner approach.

This should work in your project too, dosen`t it?

proxyUrlParsed, _ := url.Parse(proxyUrl)
c := d.NewClient(*root, *user, *password)
c.SetTransport( &http.Transport{Proxy: http.ProxyURL(proxyUrlParsed)} )
hrncacz commented 2 years ago

You are right. I have completely missed SetTransport. Thank you for advice.

chripo commented 2 years ago

You're welcome!

I'll keep this in mind to extend the documentation.