1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 05:11:31 +00:00
This commit is contained in:
astaxie 2016-03-13 11:16:19 +08:00
parent 474bdd2e6b
commit d90195061f
3 changed files with 6 additions and 14 deletions

View File

@ -24,13 +24,11 @@ package context
import ( import (
"bufio" "bufio"
"bytes"
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
@ -195,14 +193,6 @@ func (r *Response) Write(p []byte) (int, error) {
return r.ResponseWriter.Write(p) 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, // WriteHeader sends an HTTP response header with status code,
// and sets `started` to true. // and sets `started` to true.
func (r *Response) WriteHeader(code int) { func (r *Response) WriteHeader(code int) {

View File

@ -21,6 +21,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"io"
"mime" "mime"
"net/http" "net/http"
"path/filepath" "path/filepath"
@ -72,10 +73,11 @@ func (output *BeegoOutput) Body(content []byte) error {
if output.Status != 0 { if output.Status != 0 {
output.Context.ResponseWriter.WriteHeader(output.Status) output.Context.ResponseWriter.WriteHeader(output.Status)
output.Status = 0 output.Status = 0
} else {
output.Context.ResponseWriter.Started = true
} }
io.Copy(output.Context.ResponseWriter, buf)
_, err := output.Context.ResponseWriter.Copy(buf) return nil
return err
} }
// Cookie sets cookie value via given key. // Cookie sets cookie value via given key.

View File

@ -783,7 +783,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if !context.ResponseWriter.Started && context.Output.Status == 0 { if !context.ResponseWriter.Started && context.Output.Status == 0 {
if BConfig.WebConfig.AutoRender { if BConfig.WebConfig.AutoRender {
if err := execController.Render(); err != nil { if err := execController.Render(); err != nil {
panic(err) Error(err)
} }
} }
} }