File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+ package option
4+
5+ import (
6+ "log"
7+ "net/http"
8+ "net/http/httputil"
9+ )
10+
11+ // WithDebugLog logs the HTTP request and response content.
12+ // If the logger parameter is nil, it uses the default logger.
13+ //
14+ // WithDebugLog is for debugging and development purposes only.
15+ // It should not be used in production code. The behavior and interface
16+ // of WithDebugLog is not guaranteed to be stable.
17+ func WithDebugLog (logger * log.Logger ) RequestOption {
18+ return WithMiddleware (func (req * http.Request , nxt MiddlewareNext ) (* http.Response , error ) {
19+ if logger == nil {
20+ logger = log .Default ()
21+ }
22+
23+ if reqBytes , err := httputil .DumpRequest (req , true ); err == nil {
24+ logger .Printf ("Request Content:\n %s\n " , reqBytes )
25+ }
26+
27+ resp , err := nxt (req )
28+ if err != nil {
29+ return resp , err
30+ }
31+
32+ if respBytes , err := httputil .DumpResponse (resp , true ); err == nil {
33+ logger .Printf ("Response Content:\n %s\n " , respBytes )
34+ }
35+
36+ return resp , err
37+ })
38+ }
You can’t perform that action at this time.
0 commit comments