2015-03-27 23:21:30 +02:00
|
|
|
package echo
|
2015-03-01 19:45:13 +02:00
|
|
|
|
|
|
|
import (
|
2015-03-06 21:12:33 +02:00
|
|
|
"log"
|
2015-03-01 19:45:13 +02:00
|
|
|
"net/http"
|
2015-04-19 06:46:00 +02:00
|
|
|
|
|
|
|
"labstack.com/gommon/color"
|
2015-03-01 19:45:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
response struct {
|
2015-04-09 23:59:31 +02:00
|
|
|
Writer http.ResponseWriter
|
2015-03-06 21:12:33 +02:00
|
|
|
status int
|
|
|
|
size int
|
|
|
|
committed bool
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-04-09 20:04:33 +02:00
|
|
|
func (r *response) Header() http.Header {
|
2015-04-09 23:59:31 +02:00
|
|
|
return r.Writer.Header()
|
2015-04-09 20:04:33 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:50:24 +02:00
|
|
|
func (r *response) WriteHeader(n int) {
|
2015-03-06 21:12:33 +02:00
|
|
|
if r.committed {
|
|
|
|
// TODO: Warning
|
2015-04-19 06:46:00 +02:00
|
|
|
log.Println(color.Yellow("echo: response already committed"))
|
2015-03-06 21:12:33 +02:00
|
|
|
return
|
|
|
|
}
|
2015-03-25 17:50:24 +02:00
|
|
|
r.status = n
|
2015-04-09 23:59:31 +02:00
|
|
|
r.Writer.WriteHeader(n)
|
2015-03-06 21:12:33 +02:00
|
|
|
r.committed = true
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *response) Write(b []byte) (n int, err error) {
|
2015-04-09 23:59:31 +02:00
|
|
|
n, err = r.Writer.Write(b)
|
2015-03-01 19:45:13 +02:00
|
|
|
r.size += n
|
|
|
|
return n, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *response) Status() int {
|
|
|
|
return r.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *response) Size() int {
|
|
|
|
return r.size
|
|
|
|
}
|
2015-03-06 21:12:33 +02:00
|
|
|
|
2015-04-07 22:02:23 +02:00
|
|
|
func (r *response) reset(w http.ResponseWriter) {
|
2015-04-09 23:59:31 +02:00
|
|
|
r.Writer = w
|
2015-03-06 21:12:33 +02:00
|
|
|
r.committed = false
|
|
|
|
}
|