@@ -13,6 +13,7 @@ import (
1313 "github.com/stackql/any-sdk/pkg/client"
1414 "github.com/stackql/any-sdk/pkg/dto"
1515 "github.com/stackql/any-sdk/pkg/internaldto"
16+ "github.com/stackql/any-sdk/pkg/latetranslator"
1617 "github.com/stackql/any-sdk/pkg/netutils"
1718 "github.com/stackql/any-sdk/pkg/requesttranslate"
1819)
@@ -24,12 +25,14 @@ var (
2425)
2526
2627type anySdkHttpClient struct {
27- client * http.Client
28+ client * http.Client
29+ lateTranslator latetranslator.LateTranslator
2830}
2931
3032func newAnySdkHttpClient (client * http.Client ) client.AnySdkClient {
3133 return & anySdkHttpClient {
32- client : client ,
34+ client : client ,
35+ lateTranslator : latetranslator .NewNaiveLateTranslator (),
3336 }
3437}
3538
@@ -120,7 +123,11 @@ func (hc *anySdkHttpClient) Do(designation client.AnySdkDesignation, argList cli
120123 if ! isHttpRequest {
121124 return nil , fmt .Errorf ("could not cast first argument to http.Request" )
122125 }
123- httpResponse , httpResponseErr := hc .client .Do (httpReq )
126+ translatedRequest , translationErr := hc .lateTranslator .Translate (httpReq )
127+ if translationErr != nil {
128+ return nil , translationErr
129+ }
130+ httpResponse , httpResponseErr := hc .client .Do (translatedRequest )
124131 if httpResponseErr != nil {
125132 return nil , httpResponseErr
126133 }
@@ -129,19 +136,25 @@ func (hc *anySdkHttpClient) Do(designation client.AnySdkDesignation, argList cli
129136}
130137
131138type anySdkHTTPClientConfigurator struct {
132- runtimeCtx dto.RuntimeCtx
133- authUtil auth_util.AuthUtility
134- providerName string
139+ runtimeCtx dto.RuntimeCtx
140+ authUtil auth_util.AuthUtility
141+ providerName string
142+ defaultClient * http.Client
135143}
136144
137145func NewAnySdkClientConfigurator (
138146 rtCtx dto.RuntimeCtx ,
139147 provName string ,
148+ defaultClient * http.Client ,
140149) client.AnySdkClientConfigurator {
150+ if defaultClient == nil {
151+ defaultClient = http .DefaultClient
152+ }
141153 return & anySdkHTTPClientConfigurator {
142- runtimeCtx : rtCtx ,
143- authUtil : auth_util .NewAuthUtility (),
144- providerName : provName ,
154+ runtimeCtx : rtCtx ,
155+ authUtil : auth_util .NewAuthUtility (defaultClient ),
156+ providerName : provName ,
157+ defaultClient : defaultClient ,
145158 }
146159}
147160
@@ -246,7 +259,7 @@ func (cc *anySdkHTTPClientConfigurator) Auth(
246259 }
247260 return newAnySdkHttpClient (httpClient ), nil
248261 case dto .AuthNullStr :
249- httpClient := netutils .GetHTTPClient (cc .runtimeCtx , http . DefaultClient )
262+ httpClient := netutils .GetHTTPClient (cc .runtimeCtx , cc . defaultClient )
250263 return newAnySdkHttpClient (httpClient ), nil
251264 }
252265 return nil , fmt .Errorf ("could not infer auth type" )
0 commit comments