1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00
echo/response.go

52 lines
817 B
Go
Raw Normal View History

package echo
import (
"log"
"net/http"
"github.com/labstack/gommon/color"
)
type (
Response struct {
Writer http.ResponseWriter
status int
size uint64
committed bool
}
)
func (r *Response) Header() http.Header {
return r.Writer.Header()
}
func (r *Response) WriteHeader(code int) {
if r.committed {
// TODO: Warning
log.Printf("echo: %s", color.Yellow("response already committed"))
return
}
r.status = code
r.Writer.WriteHeader(code)
r.committed = true
}
func (r *Response) Write(b []byte) (n int, err error) {
n, err = r.Writer.Write(b)
r.size += uint64(n)
return n, err
}
func (r *Response) Status() int {
return r.status
}
func (r *Response) Size() uint64 {
return r.size
}
func (r *Response) reset(w http.ResponseWriter) {
r.Writer = w
r.committed = false
}