Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: enable configuration of client response interface #250

Merged
merged 1 commit into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/response.go
Expand Up @@ -23,6 +23,8 @@ import (

var _ runtime.ClientResponse = response{}

func newResponse(resp *http.Response) runtime.ClientResponse { return response{resp: resp} }

type response struct {
resp *http.Response
}
Expand Down
19 changes: 16 additions & 3 deletions client/runtime.go
Expand Up @@ -225,7 +225,7 @@ type Runtime struct {

Transport http.RoundTripper
Jar http.CookieJar
//Spec *spec.Document
// Spec *spec.Document
Host string
BasePath string
Formats strfmt.Registry
Expand All @@ -237,6 +237,7 @@ type Runtime struct {
clientOnce *sync.Once
client *http.Client
schemes []string
response ClientResponseFunc
}

// New creates a new default runtime for a swagger api runtime.Client
Expand Down Expand Up @@ -275,6 +276,7 @@ func New(host, basePath string, schemes []string) *Runtime {

rt.Debug = logger.DebugEnabled()
rt.logger = logger.StandardLogger{}
rt.response = newResponse

if len(schemes) > 0 {
rt.schemes = schemes
Expand Down Expand Up @@ -329,6 +331,7 @@ func (r *Runtime) selectScheme(schemes []string) string {
}
return scheme
}

func transportOrDefault(left, right http.RoundTripper) http.RoundTripper {
if left == nil {
return right
Expand Down Expand Up @@ -381,7 +384,7 @@ func (r *Runtime) createHttpRequest(operation *runtime.ClientOperation) (*reques
return r.DefaultAuthentication.AuthenticateRequest(req, reg)
})
}
//if auth != nil {
// if auth != nil {
// if err := auth.AuthenticateRequest(request, r.Formats); err != nil {
// return nil, err
// }
Expand Down Expand Up @@ -500,7 +503,7 @@ func (r *Runtime) Submit(operation *runtime.ClientOperation) (interface{}, error
return nil, fmt.Errorf("no consumer: %q", ct)
}
}
return readResponse.ReadResponse(response{res}, cons)
return readResponse.ReadResponse(r.response(res), cons)
}

// SetDebug changes the debug flag.
Expand All @@ -516,3 +519,13 @@ func (r *Runtime) SetLogger(logger logger.Logger) {
r.logger = logger
middleware.Logger = logger
}

type ClientResponseFunc = func(*http.Response) runtime.ClientResponse

// SetResponseReader changes the response reader implementation.
func (r *Runtime) SetResponseReader(f ClientResponseFunc) {
if f == nil {
return
}
r.response = f
}