Fix empty body error in mirror
This commit is contained in:
parent
2b73860ea5
commit
0ac6f80b50
2 changed files with 15 additions and 2 deletions
|
@ -204,7 +204,7 @@ func newReusableRequest(req *http.Request, maxBodySize int64) (*reusableRequest,
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return nil, nil, errors.New("nil input request")
|
return nil, nil, errors.New("nil input request")
|
||||||
}
|
}
|
||||||
if req.Body == nil {
|
if req.Body == nil || req.ContentLength == 0 {
|
||||||
return &reusableRequest{req: req}, nil, nil
|
return &reusableRequest{req: req}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,9 +243,22 @@ func TestCloneRequest(t *testing.T) {
|
||||||
req, err := http.NewRequest(http.MethodPost, "/", buf)
|
req, err := http.NewRequest(http.MethodPost, "/", buf)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, expectedBytes, err := newReusableRequest(req, 20)
|
rr, expectedBytes, err := newReusableRequest(req, 20)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Nil(t, expectedBytes)
|
assert.Nil(t, expectedBytes)
|
||||||
|
assert.Len(t, rr.body, 10)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("valid GET case with maxBodySize", func(t *testing.T) {
|
||||||
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, "/", buf)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
rr, expectedBytes, err := newReusableRequest(req, 20)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Nil(t, expectedBytes)
|
||||||
|
assert.Len(t, rr.body, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("no request given", func(t *testing.T) {
|
t.Run("no request given", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue