mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 19:50:56 +00:00
impove the ResponseWriter. fix #1410
This commit is contained in:
parent
e3120226fa
commit
fd4630c6dd
31
router.go
31
router.go
@ -15,10 +15,7 @@
|
|||||||
package beego
|
package beego
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -581,7 +578,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
var runMethod string
|
var runMethod string
|
||||||
var routerInfo *controllerInfo
|
var routerInfo *controllerInfo
|
||||||
|
|
||||||
w := &responseWriter{writer: rw}
|
w := &responseWriter{rw, false, 0}
|
||||||
|
|
||||||
if RunMode == "dev" {
|
if RunMode == "dev" {
|
||||||
w.Header().Set("Server", BeegoServerName)
|
w.Header().Set("Server", BeegoServerName)
|
||||||
@ -856,7 +853,7 @@ Admin:
|
|||||||
|
|
||||||
// Call WriteHeader if status code has been set changed
|
// Call WriteHeader if status code has been set changed
|
||||||
if context.Output.Status != 0 {
|
if context.Output.Status != 0 {
|
||||||
w.writer.WriteHeader(context.Output.Status)
|
w.WriteHeader(context.Output.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -895,14 +892,14 @@ func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
|
|||||||
//responseWriter is a wrapper for the http.ResponseWriter
|
//responseWriter is a wrapper for the http.ResponseWriter
|
||||||
//started set to true if response was written to then don't execute other handler
|
//started set to true if response was written to then don't execute other handler
|
||||||
type responseWriter struct {
|
type responseWriter struct {
|
||||||
writer http.ResponseWriter
|
http.ResponseWriter
|
||||||
started bool
|
started bool
|
||||||
status int
|
status int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header returns the header map that will be sent by WriteHeader.
|
// Header returns the header map that will be sent by WriteHeader.
|
||||||
func (w *responseWriter) Header() http.Header {
|
func (w *responseWriter) Header() http.Header {
|
||||||
return w.writer.Header()
|
return w.ResponseWriter.Header()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write writes the data to the connection as part of an HTTP reply,
|
// Write writes the data to the connection as part of an HTTP reply,
|
||||||
@ -910,7 +907,7 @@ func (w *responseWriter) Header() http.Header {
|
|||||||
// started means the response has sent out.
|
// started means the response has sent out.
|
||||||
func (w *responseWriter) Write(p []byte) (int, error) {
|
func (w *responseWriter) Write(p []byte) (int, error) {
|
||||||
w.started = true
|
w.started = true
|
||||||
return w.writer.Write(p)
|
return w.ResponseWriter.Write(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteHeader sends an HTTP response header with status code,
|
// WriteHeader sends an HTTP response header with status code,
|
||||||
@ -918,23 +915,7 @@ func (w *responseWriter) Write(p []byte) (int, error) {
|
|||||||
func (w *responseWriter) WriteHeader(code int) {
|
func (w *responseWriter) WriteHeader(code int) {
|
||||||
w.status = code
|
w.status = code
|
||||||
w.started = true
|
w.started = true
|
||||||
w.writer.WriteHeader(code)
|
w.ResponseWriter.WriteHeader(code)
|
||||||
}
|
|
||||||
|
|
||||||
// hijacker for http
|
|
||||||
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|
||||||
hj, ok := w.writer.(http.Hijacker)
|
|
||||||
if !ok {
|
|
||||||
return nil, nil, errors.New("webserver doesn't support hijacking")
|
|
||||||
}
|
|
||||||
return hj.Hijack()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *responseWriter) Flush() {
|
|
||||||
f, ok := w.writer.(http.Flusher)
|
|
||||||
if ok {
|
|
||||||
f.Flush()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func tourl(params map[string]string) string {
|
func tourl(params map[string]string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user