Move ResponseWriter.Flush to Flusher interface

This commit is contained in:
Adnan Maolood
2021-02-17 11:44:11 -05:00
parent fb9b50871c
commit a3c1804395
3 changed files with 21 additions and 6 deletions

View File

@@ -39,6 +39,12 @@ func main() {
// stream writes an infinite stream to w.
func stream(w gemini.ResponseWriter, r *gemini.Request) {
flusher, ok := w.(gemini.Flusher)
if !ok {
w.Status(gemini.StatusTemporaryFailure)
return
}
ch := make(chan string)
ctx, cancel := context.WithCancel(context.Background())
@@ -63,7 +69,7 @@ func stream(w gemini.ResponseWriter, r *gemini.Request) {
break
}
fmt.Fprintln(w, s)
if err := w.Flush(); err != nil {
if err := flusher.Flush(); err != nil {
cancel()
return
}