1 package httpbuffer_test 2 3 import ( 4 "fmt" 5 "io" 6 "net/http" 7 "net/http/httptest" 8 9 "vimagination.zapto.org/httpbuffer" 10 ) 11 12 func handler(w http.ResponseWriter, r *http.Request) { 13 io.WriteString(w, "Hello, World!") 14 } 15 16 func Example() { 17 w := httptest.NewRecorder() 18 r, _ := http.NewRequest(http.MethodGet, "/", nil) 19 20 handler(w, r) 21 22 fmt.Println(w.Result().ContentLength) 23 24 w = httptest.NewRecorder() 25 buf := httpbuffer.Handler{Handler: http.HandlerFunc(handler)} 26 buf.ServeHTTP(w, r) 27 28 fmt.Println(w.Result().ContentLength) 29 fmt.Println(w.Body) 30 31 // Output: 32 // -1 33 // 13 34 // Hello, World! 35 } 36