diff --git a/ctx.go b/ctx.go index 83185773..1cb231cd 100644 --- a/ctx.go +++ b/ctx.go @@ -871,7 +871,7 @@ func (ctx *Ctx) Secure() bool { // Send sets the HTTP response body. The input can be of any type, io.Reader is also supported. func (ctx *Ctx) Send(bodies ...interface{}) { // Reset response body - ctx.Fasthttp.Response.ResetBody() + ctx.SendString("") // Write response body ctx.Write(bodies...) } diff --git a/ctx_test.go b/ctx_test.go index 2bd4d896..79b815eb 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -1515,6 +1515,20 @@ func Test_Ctx_SendBytes(t *testing.T) { utils.AssertEqual(t, "Hello, World!", string(ctx.Fasthttp.Response.Body())) } +// go test -v -run=^$ -bench=Benchmark_Ctx_Benchmark_Ctx_SendBytes -benchmem -count=4 +func Benchmark_Ctx_SendBytes(b *testing.B) { + app := New() + c := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(c) + var byt = []byte("Hello, World!") + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + c.SendBytes(byt) + } + utils.AssertEqual(b, "Hello, World!", string(c.Fasthttp.Response.Body())) +} + // go test -run Test_Ctx_SendStatus func Test_Ctx_SendStatus(t *testing.T) { t.Parallel()