dump HTTP request/response for function test (#2348)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -192,12 +193,28 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
|
|||||||
req.Header.Set(headerKeyValue[0], headerKeyValue[1])
|
req.Header.Set(headerKeyValue[0], headerKeyValue[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if console.Verbosity >= 2 {
|
||||||
|
dumpReq, err := httputil.DumpRequestOut(req, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
console.Verbose(2, string(dumpReq))
|
||||||
|
}
|
||||||
|
|
||||||
hc := &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}
|
hc := &http.Client{Transport: otelhttp.NewTransport(http.DefaultTransport)}
|
||||||
resp, err := hc.Do(req.WithContext(ctx))
|
resp, err := hc.Do(req.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error executing HTTP request")
|
return nil, errors.Wrap(err, "error executing HTTP request")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if console.Verbosity >= 2 {
|
||||||
|
dumpRes, err := httputil.DumpResponse(resp, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
console.Verbose(2, string(dumpRes))
|
||||||
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user