Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty http request body in Connection.Call #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ func (c *Connection) Call(ctx context.Context, targetUrl string, p RequestOpts)
retries = c.Retries
}
var req *http.Request
reqBodyBuf, err := ioutil.ReadAll(p.Body)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Body is used to upload objects so could easily be a 5G file which we don't want to buffer in memory.

Where are you seeing this problem?

There are quite a few possible workaround, but to suggest one I need more context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my very late rseponse. I missed it earlier

I see the problem is fixed in d2de41c to some extent. Maybe it should always Seek(0, io.SeekStart) , not only in 401 ?

if err != nil {
return
}
reader := bytes.NewReader(reqBodyBuf)
for {
var authToken string
if targetUrl, authToken, err = c.getUrlAndAuthToken(ctx, targetUrl, p.OnReAuth); err != nil {
Expand All @@ -735,11 +740,9 @@ func (c *Connection) Call(ctx context.Context, targetUrl string, p RequestOpts)
}
timer := time.NewTimer(c.ConnectTimeout)
defer timer.Stop()
reader := p.Body
if reader != nil {
reader = newWatchdogReader(reader, c.Timeout, timer)
}
req, err = http.NewRequestWithContext(ctx, p.Operation, URL.String(), reader)
reader.Reset(reqBodyBuf) // or reader.Seek(0, io.SeekStart) ?
watchdogReader := newWatchdogReader(reader, c.Timeout, timer)
req, err = http.NewRequestWithContext(ctx, p.Operation, URL.String(), watchdogReader)
if err != nil {
return
}
Expand Down