aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context/response.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/context/response.go')
-rw-r--r--modules/context/response.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/context/response.go b/modules/context/response.go
index 1881ec7b33..bdbbb97af7 100644
--- a/modules/context/response.go
+++ b/modules/context/response.go
@@ -12,6 +12,7 @@ type ResponseWriter interface {
Flush()
Status() int
Before(func(ResponseWriter))
+ Size() int
}
var (
@@ -21,11 +22,17 @@ var (
// Response represents a response
type Response struct {
http.ResponseWriter
+ written int
status int
befores []func(ResponseWriter)
beforeExecuted bool
}
+// Size return written size
+func (r *Response) Size() int {
+ return r.written
+}
+
// Write writes bytes to HTTP endpoint
func (r *Response) Write(bs []byte) (int, error) {
if !r.beforeExecuted {
@@ -35,8 +42,9 @@ func (r *Response) Write(bs []byte) (int, error) {
r.beforeExecuted = true
}
size, err := r.ResponseWriter.Write(bs)
+ r.written += size
if err != nil {
- return 0, err
+ return size, err
}
if r.status == 0 {
r.WriteHeader(200)