go-resty / resty

Simple HTTP and REST client library for Go
MIT License
9.98k stars 706 forks source link

The request with SetFileReader retry time great than 1 will has issues #770

Open ybdx opened 8 months ago

ybdx commented 8 months ago

Below is the SetFileReader function code

func (r *Request) SetFileReader(param, fileName string, reader io.Reader) *Request {
    r.isMultiPart = true
    r.multipartFiles = append(r.multipartFiles, &File{
        Name:      fileName,
        ParamName: param,
        Reader:    reader,
    })
    return r
}

When we first use the reader to read content, the reader current index will move to the end. When we retry it again, the current index is in the end, we will lost the content from the start to the end. This means the second time we read the content is empty.

jeevatkm commented 7 months ago

@ybdx Thanks for reporting it; I will analyze it.

jeevatkm commented 2 days ago

@ybdx I know this issue is aged. I'm sorry for getting back late. I wanted to check whether https://pkg.go.dev/github.com/go-resty/resty/v2#Client.SetRetryResetReaders has addressed your usage. This option enables Resty to reset the reader if io.ReadSeeker is supported.