Skip to content

Commit

Permalink
Merge pull request #250 from Kunde21/custom_clientresponse
Browse files Browse the repository at this point in the history
client: enable configuration of client response interface
  • Loading branch information
casualjim committed Oct 14, 2022
2 parents 53ffffd + a7d5226 commit c12369b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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
}

0 comments on commit c12369b

Please sign in to comment.