mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
f134ea3aea
Signed-off-by: Vishal Rana <vr@labstack.com>
52 lines
780 B
Go
52 lines
780 B
Go
package echo
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"labstack.com/gommon/color"
|
|
)
|
|
|
|
type (
|
|
response struct {
|
|
Writer http.ResponseWriter
|
|
status int
|
|
size int
|
|
committed bool
|
|
}
|
|
)
|
|
|
|
func (r *response) Header() http.Header {
|
|
return r.Writer.Header()
|
|
}
|
|
|
|
func (r *response) WriteHeader(n int) {
|
|
if r.committed {
|
|
// TODO: Warning
|
|
log.Println(color.Yellow("echo: response already committed"))
|
|
return
|
|
}
|
|
r.status = n
|
|
r.Writer.WriteHeader(n)
|
|
r.committed = true
|
|
}
|
|
|
|
func (r *response) Write(b []byte) (n int, err error) {
|
|
n, err = r.Writer.Write(b)
|
|
r.size += n
|
|
return n, err
|
|
}
|
|
|
|
func (r *response) Status() int {
|
|
return r.status
|
|
}
|
|
|
|
func (r *response) Size() int {
|
|
return r.size
|
|
}
|
|
|
|
func (r *response) reset(w http.ResponseWriter) {
|
|
r.Writer = w
|
|
r.committed = false
|
|
}
|