1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00
echo/response.go
Vishal Rana 05e8fee3de Added response already committed logic
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-03-06 11:12:33 -08:00

71 lines
1.1 KiB
Go

package bolt
import (
"bufio"
"errors"
"log"
"net"
"net/http"
)
type (
response struct {
http.ResponseWriter
status int
size int
committed bool
}
)
func (r *response) WriteHeader(c int) {
if r.committed {
// TODO: Warning
log.Println("bolt: response already committed")
return
}
r.status = c
r.ResponseWriter.WriteHeader(c)
r.committed = true
}
func (r *response) Write(b []byte) (n int, err error) {
n, err = r.ResponseWriter.Write(b)
r.size += n
return n, err
}
func (r *response) CloseNotify() <-chan bool {
cn, ok := r.ResponseWriter.(http.CloseNotifier)
if !ok {
return nil
}
return cn.CloseNotify()
}
func (r *response) Flusher() {
if f, ok := r.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}
func (r *response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
h, ok := r.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("hijacker interface not supported")
}
return h.Hijack()
}
func (r *response) Status() int {
return r.status
}
func (r *response) Size() int {
return r.size
}
func (r *response) reset(rw http.ResponseWriter) {
r.ResponseWriter = rw
r.committed = false
}