XHTTP client: Define Request.GetBody() for packet-up so h2 can replay after GOAWAY (#6632)

https://github.com/XTLS/Xray-core/pull/6632#issuecomment-5430735467

---------

Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
This commit is contained in:
FunLay123
2026-08-26 20:41:43 +00:00
committed by GitHub
co-authored by 风扇滑翔翼
parent 77f98eba09
commit dffc7ada5e
2 changed files with 46 additions and 5 deletions
@@ -1,9 +1,13 @@
package splithttp_test
import (
"io"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
. "github.com/xtls/xray-core/transport/internet/splithttp"
)
@@ -77,3 +81,35 @@ func Test_GetNormalizedPath(t *testing.T) {
})
}
}
func Test_FillPacketRequest_GetBody(t *testing.T) {
data := []byte("hello xray")
payload := buf.MergeBytes(nil, data)
req, err := http.NewRequest("POST", "https://example.com/", nil)
common.Must(err)
config := &Config{}
config.FillPacketRequest(req, "sess", "0", payload)
if req.GetBody == nil {
t.Fatalf("Expected GetBody to be set")
}
first, err := io.ReadAll(req.Body)
common.Must(err)
if string(data) != string(first) {
t.Fatalf("Body mismatch. Format %q and %q are not equal", data, first)
}
body2, err := req.GetBody()
common.Must(err)
second, err := io.ReadAll(body2)
common.Must(err)
if string(data) != string(second) {
t.Fatalf("Replayed body mismatch. Format %q and %q are not equal", data, second)
}
}