diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index aab9b2ed..e305d9d5 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "io" "io/ioutil" "math" "net" @@ -81,15 +80,14 @@ var ( ErrStrCallbackSignatureIsWrong = "wrong signature" ) -func getClonedData(requestURL *url.URL, r *bytes.Buffer) string { +func getClonedData(requestURL *url.URL, data []byte) string { if strings.Index(requestURL.String(), "uploadImg") >= 0 { return "binary content" } - retVal := string(r.Bytes()) - if len(retVal) > maxDataSizeDontOutput { + if len(data) > maxDataSizeDontOutput { return "request data is too large" } - return retVal + return string(data) } func NewDefAPIConfig() (conf *APIConfig) { @@ -101,10 +99,16 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http. exceedLimitRetryCount := 0 recoverableErrorRetryCount := 0 for { - savedBuf := new(bytes.Buffer) + var savedBuf []byte request := handleRequest() if request.Body != nil { - request.Body = ioutil.NopCloser(io.TeeReader(request.Body, savedBuf)) + savedBuf2, err2 := ioutil.ReadAll(request.Body) + if err2 == nil { + savedBuf = savedBuf2 + request.Body = ioutil.NopCloser(bytes.NewReader(savedBuf)) + } else { + baseapi.SugarLogger.Warnf("AccessPlatformAPIWithRetry failed with err:%v", err2) + } } beginTime := time.Now() trackInfo := request.Header.Get(KeyTrackInfo)