mirror of https://github.com/gin-gonic/gin.git
Refactors response_writer.go
This commit is contained in:
parent
251b73fc70
commit
34b1d0262e
|
@ -6,7 +6,6 @@ package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,6 +13,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NoWritten = -1
|
NoWritten = -1
|
||||||
|
DefaultStatus = 200
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -31,15 +31,15 @@ type (
|
||||||
|
|
||||||
responseWriter struct {
|
responseWriter struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
status int
|
|
||||||
size int
|
size int
|
||||||
|
status int
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *responseWriter) reset(writer http.ResponseWriter) {
|
func (w *responseWriter) reset(writer http.ResponseWriter) {
|
||||||
w.ResponseWriter = writer
|
w.ResponseWriter = writer
|
||||||
w.status = 200
|
|
||||||
w.size = NoWritten
|
w.size = NoWritten
|
||||||
|
w.status = DefaultStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *responseWriter) WriteHeader(code int) {
|
func (w *responseWriter) WriteHeader(code int) {
|
||||||
|
@ -90,8 +90,5 @@ func (w *responseWriter) CloseNotify() <-chan bool {
|
||||||
|
|
||||||
// Implements the http.Flush interface
|
// Implements the http.Flush interface
|
||||||
func (w *responseWriter) Flush() {
|
func (w *responseWriter) Flush() {
|
||||||
flusher, ok := w.ResponseWriter.(http.Flusher)
|
w.ResponseWriter.(http.Flusher).Flush()
|
||||||
if ok {
|
|
||||||
flusher.Flush()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue