Exemple #1
0
func byInspecting() autorest.RespondDecorator {
	return func(r autorest.Responder) autorest.Responder {
		return autorest.ResponderFunc(func(resp *http.Response) error {
			fmt.Printf("Inspecting Response: %s for %s %s\n", resp.Status, resp.Request.Method, resp.Request.URL)
			return r.Respond(resp)
		})
	}
}
// ByInspecting provides a convenient way to hook into each HTTP response of a client.
func ByInspecting(callbacks ...ResponseObserver) autorest.RespondDecorator {
	return func(r autorest.Responder) autorest.Responder {
		return autorest.ResponderFunc(func(resp *http.Response) error {
			fmt.Printf("Inspecting Response: %s for %s %s\n", resp.Status, resp.Request.Method, resp.Request.URL)
			for _, cb := range callbacks {
				if cb != nil {
					cb(resp)
				}
			}
			return r.Respond(resp)
		})
	}
}
Exemple #3
0
// tracingRespondDecorator returns an autorest.RespondDecorator that
// logs responses at trace level.
func tracingRespondDecorator(logger loggo.Logger) autorest.RespondDecorator {
	return func(r autorest.Responder) autorest.Responder {
		return autorest.ResponderFunc(func(resp *http.Response) error {
			dump, err := httputil.DumpResponse(resp, true)
			if err != nil {
				logger.Tracef("failed to dump response: %v", err)
				logger.Tracef("%+v", resp)
			} else {
				logger.Tracef("%s", dump)
			}
			return r.Respond(resp)
		})
	}
}