supabase-community / postgrest-go

Isomorphic Go client for PostgREST. (Now Updating)
https://supabase.io
Apache License 2.0
170 stars 27 forks source link

Allow custom Transport Configuration #39

Closed Fritte795 closed 8 months ago

Fritte795 commented 10 months ago

Feature request

Is your feature request related to a problem? Please describe.

Typically the default implementation of Transport http.DefaultTransport does not accept self signed certificates. In some environments PKIs are used with Root- or Intermediate-CAs not signed by an official CA. Therefore it might be necessary to customize the transport used by a client.

With the current implementation this is not possible as the custom implemented RoundTrip always calls http.DefaultTransport.RoundTrip().

Describe the solution you'd like

It should be possibile to define the wrapping Transport of the custom transport in client.go. An usage could look like this:

func main() {
    c := postgrest.NewClient("", "", nil)

    c.ClientTransport.Parent = &http.Transport{
        TLSClientConfig: &tls.Config{
            // Custom tls config
        },
    }
}

Few things need to be changed for this:

  1. The Client.clientTransport needs to be exposed
  2. I would recommend to use a pointer instead of the struct value to guarantee a shared/synced transport between Client.session.Transport and Client.clientTransport a. Client.clientTransport is stuttering. Could it not be Client.transport or exposed Client.Transport?
  3. Add a "base" Parent to transport a. basic http.RoundTripper that will be called in RoundTrip instead of http.DefaultTransport.RoundTrip() b. Initialize transport.Parent with http.DefaultTransport to keep old behavior.

A pull request will be created after this issue.