diff --git a/context/context.go b/context/context.go index 63a1313d..ab3a3d3f 100644 --- a/context/context.go +++ b/context/context.go @@ -24,13 +24,11 @@ package context import ( "bufio" - "bytes" "crypto/hmac" "crypto/sha1" "encoding/base64" "errors" "fmt" - "io" "net" "net/http" "strconv" @@ -195,14 +193,6 @@ func (r *Response) Write(p []byte) (int, error) { return r.ResponseWriter.Write(p) } -// Copy writes the data to the connection as part of an HTTP reply, -// and sets `started` to true. -// started means the response has sent out. -func (r *Response) Copy(buf *bytes.Buffer) (int64, error) { - r.Started = true - return io.Copy(r.ResponseWriter, buf) -} - // WriteHeader sends an HTTP response header with status code, // and sets `started` to true. func (r *Response) WriteHeader(code int) { diff --git a/context/output.go b/context/output.go index 17404702..ea5498c0 100644 --- a/context/output.go +++ b/context/output.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "html/template" + "io" "mime" "net/http" "path/filepath" @@ -72,10 +73,11 @@ func (output *BeegoOutput) Body(content []byte) error { if output.Status != 0 { output.Context.ResponseWriter.WriteHeader(output.Status) output.Status = 0 + } else { + output.Context.ResponseWriter.Started = true } - - _, err := output.Context.ResponseWriter.Copy(buf) - return err + io.Copy(output.Context.ResponseWriter, buf) + return nil } // Cookie sets cookie value via given key. diff --git a/router.go b/router.go index d0bf534f..5d0e1970 100644 --- a/router.go +++ b/router.go @@ -783,7 +783,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) if !context.ResponseWriter.Started && context.Output.Status == 0 { if BConfig.WebConfig.AutoRender { if err := execController.Render(); err != nil { - panic(err) + Error(err) } } }