Sfoglia il codice sorgente

gin.responseWriter implements http.Flusher and http.CloseNotifier

Manu Mtz-Almeida 11 anni fa
parent
commit
8f1bbc6b6a
1 ha cambiato i file con 16 aggiunte e 0 eliminazioni
  1. 16 0
      response_writer.go

+ 16 - 0
response_writer.go

@@ -12,6 +12,9 @@ type (
 	ResponseWriter interface {
 		http.ResponseWriter
 		http.Hijacker
+		http.Flusher
+		http.CloseNotifier
+
 		Status() int
 		Written() bool
 		WriteHeaderNow()
@@ -67,3 +70,16 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
 	}
 	return hijacker.Hijack()
 }
+
+// Implements the http.CloseNotify interface
+func (w *responseWriter) CloseNotify() <-chan bool {
+	return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
+}
+
+// Implements the http.Flush interface
+func (w *responseWriter) Flush() {
+	flusher, ok := w.ResponseWriter.(http.Flusher)
+	if ok {
+		flusher.Flush()
+	}
+}