rpcenc: Fix POST read

This commit is contained in:
Łukasz Magiera 2021-07-30 13:03:31 +02:00
parent 0c809d3a5f
commit 555c402ba3
2 changed files with 24 additions and 0 deletions

View File

@ -254,6 +254,10 @@ func (w *rpcReader) Close() error {
}
func (w *rpcReader) redirect(to string) bool {
if w.postBody != nil {
return false
}
done := false
w.beginOnce.Do(func() {

View File

@ -10,6 +10,7 @@ import (
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
@ -23,6 +24,18 @@ func (h *ReaderHandler) ReadAllApi(ctx context.Context, r io.Reader) ([]byte, er
return h.readApi(ctx, r)
}
func (h *ReaderHandler) ReadStartAndApi(ctx context.Context, r io.Reader) ([]byte, error) {
n, err := r.Read([]byte{0})
if err != nil {
return nil, err
}
if n != 1 {
return nil, xerrors.Errorf("not one")
}
return h.readApi(ctx, r)
}
func (h *ReaderHandler) ReadAll(ctx context.Context, r io.Reader) ([]byte, error) {
return ioutil.ReadAll(r)
}
@ -121,6 +134,7 @@ func TestReaderRedirect(t *testing.T) {
var redirClient struct {
ReadAllApi func(ctx context.Context, r io.Reader) ([]byte, error)
ReadStartAndApi func(ctx context.Context, r io.Reader) ([]byte, error)
}
{
@ -143,7 +157,13 @@ func TestReaderRedirect(t *testing.T) {
defer closer()
}
// redirect
read, err := redirClient.ReadAllApi(context.TODO(), strings.NewReader("rediracted pooooootato"))
require.NoError(t, err)
require.Equal(t, "rediracted pooooootato", string(read), "potatoes weren't equal")
// proxy (because we started reading locally)
read, err = redirClient.ReadStartAndApi(context.TODO(), strings.NewReader("rediracted pooooootato"))
require.NoError(t, err)
require.Equal(t, "ediracted pooooootato", string(read), "otatoes weren't equal")
}