mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 05:16:35 +08:00
Implement io.ReaderFrom on responseWriter
This interface is implemented on the standard net/http response object in order to unlock some optimizations around sendfile. In the same vein as the other optional interfaces, calling ReadFrom will result in a runtime panic if the underling http.ResponseWriter doesn't implement it.
This commit is contained in:
parent
f931d1ea80
commit
9555743a47
@ -22,6 +22,7 @@ type (
|
|||||||
http.Hijacker
|
http.Hijacker
|
||||||
http.Flusher
|
http.Flusher
|
||||||
http.CloseNotifier
|
http.CloseNotifier
|
||||||
|
io.ReaderFrom
|
||||||
|
|
||||||
// Returns the HTTP response status code of the current request.
|
// Returns the HTTP response status code of the current request.
|
||||||
Status() int
|
Status() int
|
||||||
@ -114,3 +115,13 @@ func (w *responseWriter) CloseNotify() <-chan bool {
|
|||||||
func (w *responseWriter) Flush() {
|
func (w *responseWriter) Flush() {
|
||||||
w.ResponseWriter.(http.Flusher).Flush()
|
w.ResponseWriter.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements the io.ReaderFrom interface
|
||||||
|
func (w *responseWriter) ReadFrom(r io.Reader) (n int64, err error) {
|
||||||
|
if w.size < 0 {
|
||||||
|
w.size = 0
|
||||||
|
}
|
||||||
|
n, err = w.ResponseWriter.(io.ReaderFrom).ReadFrom(r)
|
||||||
|
w.size += n
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user