mirror of
https://github.com/astaxie/beego.git
synced 2025-06-12 08:20:39 +00:00
fix #1669 write empty body panic error
This commit is contained in:
@ -24,11 +24,13 @@ package context
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@ -184,6 +186,14 @@ func (w *Response) Write(p []byte) (int, error) {
|
||||
return w.ResponseWriter.Write(p)
|
||||
}
|
||||
|
||||
// Write 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 (w *Response) Copy(buf *bytes.Buffer) (int64, error) {
|
||||
w.Started = true
|
||||
return io.Copy(w.ResponseWriter, buf)
|
||||
}
|
||||
|
||||
// WriteHeader sends an HTTP response header with status code,
|
||||
// and sets `started` to true.
|
||||
func (w *Response) WriteHeader(code int) {
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
@ -75,7 +74,7 @@ func (output *BeegoOutput) Body(content []byte) {
|
||||
output.Status = 0
|
||||
}
|
||||
|
||||
io.Copy(output.Context.ResponseWriter, buf)
|
||||
output.Context.ResponseWriter.Copy(buf)
|
||||
}
|
||||
|
||||
// Cookie sets cookie value via given key.
|
||||
|
Reference in New Issue
Block a user