@@ -11,8 +11,8 @@ import (
1111 "github.com/databricks/cli/internal/testutil"
1212 "github.com/databricks/cli/libs/testserver"
1313 "github.com/databricks/databricks-sdk-go/apierr"
14- "github.com/databricks/databricks-sdk-go/client"
1514 "github.com/databricks/databricks-sdk-go/config"
15+ "github.com/databricks/databricks-sdk-go/httpclient"
1616 "github.com/stretchr/testify/assert"
1717 "github.com/stretchr/testify/require"
1818)
@@ -22,7 +22,7 @@ type ProxyServer struct {
2222
2323 t testutil.TestingT
2424
25- apiClient * client. DatabricksClient
25+ apiClient * httpclient. ApiClient
2626 RequestCallback func (request * testserver.Request )
2727 ResponseCallback func (request * testserver.Request , response * testserver.EncodedResponse )
2828}
@@ -47,8 +47,10 @@ func New(t testutil.TestingT) *ProxyServer {
4747 // In CI test environments this would read the appropriate environment
4848 // variables.
4949 var err error
50- s .apiClient , err = client .New (& config.Config {})
50+ cfg := & config.Config {}
51+ clientCfg , err := config .HTTPClientConfigFromConfig (cfg )
5152 require .NoError (t , err )
53+ s .apiClient = httpclient .NewApiClient (clientCfg )
5254
5355 // Set up the proxy handler as the default handler for all requests.
5456 server := httptest .NewServer (http .HandlerFunc (s .proxyToCloud ))
@@ -102,7 +104,29 @@ func (s *ProxyServer) proxyToCloud(w http.ResponseWriter, r *http.Request) {
102104
103105 reqBody := s .reqBody (request )
104106 respBody := bytes.Buffer {}
105- err := s .apiClient .Do (context .Background (), r .Method , r .URL .Path , headers , queryParams , reqBody , & respBody )
107+
108+ // List of response headers to pass through to the client.
109+ // We can extend this code to pass all X-Databricks headers if we introduce a
110+ // more powerful visitor like `WithRequestHeaders` to the SDK. That is left
111+ // as a future exercise for now.
112+ includeResponseHeaders := []string {"X-Databricks-Org-Id" }
113+ responseHeaders := make (map [string ]* string )
114+
115+ visitors := []httpclient.DoOption {
116+ httpclient .WithRequestHeaders (headers ),
117+ httpclient .WithQueryParameters (queryParams ),
118+ httpclient .WithRequestData (reqBody ),
119+ httpclient .WithResponseUnmarshal (& respBody ),
120+ }
121+
122+ for _ , header := range includeResponseHeaders {
123+ responseHeaders [header ] = new (string )
124+ visitors = append (visitors , httpclient .WithResponseHeader (header , responseHeaders [header ]))
125+ }
126+
127+ err := s .apiClient .Do (context .Background (), r .Method , r .URL .Path ,
128+ visitors ... ,
129+ )
106130
107131 var encodedResponse * testserver.EncodedResponse
108132
@@ -142,6 +166,12 @@ func (s *ProxyServer) proxyToCloud(w http.ResponseWriter, r *http.Request) {
142166 }
143167
144168 // Send response to client.
169+ if len (responseHeaders ) > 0 {
170+ for k , v := range responseHeaders {
171+ w .Header ()[k ] = []string {* v }
172+ }
173+ }
174+
145175 w .WriteHeader (encodedResponse .StatusCode )
146176
147177 _ , err = w .Write (encodedResponse .Body )
0 commit comments