From 0d0e179d7bf5816e421acccc9bfc0cb2c4cbb73a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 11 Nov 2015 11:09:31 +0200 Subject: [PATCH] Added RequestCtx.SetResponseBody helper function --- server.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 84d5c00..2725bfa 100644 --- a/server.go +++ b/server.go @@ -239,9 +239,15 @@ func (ctx *RequestCtx) Error(msg string, statusCode int) { // // Success calls are ignored after TimeoutError call. func (ctx *RequestCtx) Success(contentType string, body []byte) { - resp := &ctx.Response - resp.Header.SetBytesK(strContentType, contentType) - resp.Body = append(resp.Body, body...) + ctx.Response.Header.SetBytesK(strContentType, contentType) + ctx.SetResponseBody(body) +} + +// SetResponseBody sets response body to the given value. +// +// It is safe modifying body buffer after the function return. +func (ctx *RequestCtx) SetResponseBody(body []byte) { + ctx.Response.Body = append(ctx.Response.Body[:0], body...) } // Logger returns logger, which may be used for logging arbitrary