Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easy chunked responses and buffering for the net/http package

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages