🚀 Improve Send

pull/614/head
Fenny 2020-07-15 15:26:05 +02:00
parent 9275592a51
commit ad2052cf8f
2 changed files with 15 additions and 1 deletions

2
ctx.go
View File

@ -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...)
}

View File

@ -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()