Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Jan 22, 2024
1 parent cf4dcb9 commit 52a0763
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions kiota_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ import (
"time"
)

type optionsType int

const (
OptionRetryHandler optionsType = iota
OptionRedirectHandler
OptionCompressionHandler
OptionParametersNameDecodingHandler
OptionUserAgentHandler
OptionHeadersInspectionHandler
)

// GetClientWithProxySettings creates a new default net/http client with a proxy url and default middleware
// Not providing any middleware would result in having default middleware provided
func GetClientWithProxySettings(proxyUrlStr string, middleware ...Middleware) (*nethttp.Client, error) {
Expand Down Expand Up @@ -89,7 +78,7 @@ func getDefaultClientWithoutMiddleware() *nethttp.Client {

// GetDefaultMiddlewares creates a new default set of middlewares for the Kiota request adapter
func GetDefaultMiddlewares() []Middleware {
return getDefaultMiddleWare(make(map[optionsType]Middleware))
return getDefaultMiddleWare(make(map[abs.RequestOptionKey]Middleware))
}

// GetDefaultMiddlewaresWithOptions creates a new default set of middlewares for the Kiota request adapter with options
Expand All @@ -99,22 +88,22 @@ func GetDefaultMiddlewaresWithOptions(requestOptions ...abs.RequestOption) ([]Mi
}

// map of middleware options
middlewareMap := make(map[optionsType]Middleware)
middlewareMap := make(map[abs.RequestOptionKey]Middleware)

for _, element := range requestOptions {
switch v := element.(type) {
case *RetryHandlerOptions:
middlewareMap[OptionRetryHandler] = NewRetryHandlerWithOptions(*v)
middlewareMap[retryKeyValue] = NewRetryHandlerWithOptions(*v)
case *RedirectHandlerOptions:
middlewareMap[OptionRedirectHandler] = NewRedirectHandlerWithOptions(*v)
middlewareMap[redirectKeyValue] = NewRedirectHandlerWithOptions(*v)
case *CompressionOptions:
middlewareMap[OptionCompressionHandler] = NewCompressionHandlerWithOptions(*v)
middlewareMap[compressKey] = NewCompressionHandlerWithOptions(*v)
case *ParametersNameDecodingOptions:
middlewareMap[OptionParametersNameDecodingHandler] = NewParametersNameDecodingHandlerWithOptions(*v)
middlewareMap[parametersNameDecodingKeyValue] = NewParametersNameDecodingHandlerWithOptions(*v)
case *UserAgentHandlerOptions:
middlewareMap[OptionUserAgentHandler] = NewUserAgentHandlerWithOptions(v)
middlewareMap[userAgentKeyValue] = NewUserAgentHandlerWithOptions(v)
case *HeadersInspectionOptions:
middlewareMap[OptionHeadersInspectionHandler] = NewHeadersInspectionHandlerWithOptions(*v)
middlewareMap[headersInspectionKeyValue] = NewHeadersInspectionHandlerWithOptions(*v)
default:
// none of the above types
return nil, errors.New("unsupported option type")
Expand All @@ -126,24 +115,24 @@ func GetDefaultMiddlewaresWithOptions(requestOptions ...abs.RequestOption) ([]Mi
}

// getDefaultMiddleWare creates a new default set of middlewares for the Kiota request adapter
func getDefaultMiddleWare(middlewareMap map[optionsType]Middleware) []Middleware {
middlewareSource := map[optionsType]func() Middleware{
OptionRetryHandler: func() Middleware {
func getDefaultMiddleWare(middlewareMap map[abs.RequestOptionKey]Middleware) []Middleware {
middlewareSource := map[abs.RequestOptionKey]func() Middleware{
retryKeyValue: func() Middleware {
return NewRetryHandler()
},
OptionRedirectHandler: func() Middleware {
redirectKeyValue: func() Middleware {
return NewRedirectHandler()
},
OptionCompressionHandler: func() Middleware {
compressKey: func() Middleware {
return NewCompressionHandler()
},
OptionParametersNameDecodingHandler: func() Middleware {
parametersNameDecodingKeyValue: func() Middleware {
return NewParametersNameDecodingHandler()
},
OptionUserAgentHandler: func() Middleware {
userAgentKeyValue: func() Middleware {
return NewUserAgentHandler()
},
OptionHeadersInspectionHandler: func() Middleware {
headersInspectionKeyValue: func() Middleware {
return NewHeadersInspectionHandler()
},
}
Expand Down

0 comments on commit 52a0763

Please sign in to comment.