Merge pull request #3431 from dmcgowan/fix-nil-body
Fix bug in setting request body
This commit is contained in:
commit
5631fe3b32
@ -230,9 +230,16 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
|
|||||||
|
|
||||||
pr, pw := io.Pipe()
|
pr, pw := io.Pipe()
|
||||||
respC := make(chan *http.Response, 1)
|
respC := make(chan *http.Response, 1)
|
||||||
|
body := ioutil.NopCloser(pr)
|
||||||
|
|
||||||
req.body = func() (io.ReadCloser, error) {
|
req.body = func() (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(pr), nil
|
if body == nil {
|
||||||
|
return nil, errors.New("cannot reuse body, request must be retried")
|
||||||
|
}
|
||||||
|
// Only use the body once since pipe cannot be seeked
|
||||||
|
ob := body
|
||||||
|
body = nil
|
||||||
|
return ob, nil
|
||||||
}
|
}
|
||||||
req.size = desc.Size
|
req.size = desc.Size
|
||||||
|
|
||||||
|
@ -495,6 +495,11 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
|
|||||||
}
|
}
|
||||||
req.Header = r.header
|
req.Header = r.header
|
||||||
if r.body != nil {
|
if r.body != nil {
|
||||||
|
body, err := r.body()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Body = body
|
||||||
req.GetBody = r.body
|
req.GetBody = r.body
|
||||||
if r.size > 0 {
|
if r.size > 0 {
|
||||||
req.ContentLength = r.size
|
req.ContentLength = r.size
|
||||||
|
Loading…
Reference in New Issue
Block a user