nandlabs / go-commons

A common collection of utilities for Go programming language
Apache License 2.0
2 stars 2 forks source link

Rest Client HTTP/HTTPS env proxy #50

Closed nandagopalan closed 6 months ago

nandagopalan commented 1 year ago

The rest.Client#UseEnvProxy currently does not specify if the proxy is for HTTP or HTTPs update the function to include the protocol as well.

rajkumarGosavi commented 1 year ago

Hi @neo7337 @nandagopalan I would like to implement this.

Can you please guide me with the following doubts:

  1. Do we need to now pass the protocol as a parameter in the UseEnvProxy function?
  2. If the above is true then given that the protocol is https do we need to set the TLSConfig in the SetProxy function?

Let me know if I am missing something here.

Thank you!!

nandagopalan commented 12 months ago

Hi @rajkumarGosavi, Thank you for your interest. I have assigned this issue to you. The idea is to just ensure that there are options for using different proxies for http and https. And each may have a different credentials too. ( we will stick to basic auth here)

Upon revisiting the code , This appears to be a complete revamp of the proxy setting in the library. At the moment the code here appears to be incorrect as its using the builtin ProxyURL returns a proxy function (for use in a Transport) that always returns the same URL. as per the documentation. This hasn't been tested out.

As a part of this issue we need to.

1) Update Client Struct to hold config for both http and https proxy details along with credentials for them (currently one one credential supported allow both of them to be used). This can be done by leveraging the Builtin Proxy Config and renaming the current proxy credential to httpProxyCredential and httpsProxyCredential respectively. The config member of the client will be defaulted to Environment configuration.

  1. When the Transport is initialised, set the value to the c.config.ProxyFunc() ( refer to doco here )

  2. Add the protocol as as enum variadic parameter to with enum type ( Http and Https) to the following signature

set proxy

https://github.com/nandlabs/go-commons/blob/dc763df5cef75f151866cd782644bd0b561d0e57/clients/rest/rest.go#L174

The above 2 functions will update the client#Config struct with appropriate values, set credentials per type as well as update the httpClient.Transport#Proxy to a new function by invoking client.proxyConfig#ProxyFunc()

  1. We also need to update the proxy auth header for the outbound request based on the request url protocol if the protocol specific auth value in the client struct is not empty.
nandagopalan commented 6 months ago

Closing this issue.