Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 825 Bytes

Readme.md

File metadata and controls

37 lines (28 loc) · 825 Bytes

httpflusher

Test

Here is httpflusher, to help you with your chunked responses and buffering of the HTTP protocol endeavors.

http.ResponseWriter + automatic http.Flusher.

Sample

package main

import (
	"net/http"
	"time"

	"github.com/widemeshio/httpflusher"
)

func main() {
	var chunkedEndpoint = func(w http.ResponseWriter, req *http.Request) {
		w = httpflusher.NewResponseWriter(w)
		w.WriteHeader(200)
		w.Write([]byte("log-line-1\n"))
		time.Sleep(time.Second)
		w.Write([]byte("log-line-2\n"))
	}
	http.HandleFunc("/stream-logs", chunkedEndpoint)
	http.ListenAndServe(":8090", nil)
}

Run:

$ curl --no-buffer localhost:8090/stream-logs