Created
January 5, 2015 20:11
-
-
Save lantins/25a7464eb3f2068c22b4 to your computer and use it in GitHub Desktop.
Revisions
-
lantins created this gist
Jan 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ // proxyWriter is used to track final status and size of the // response sent to the client type proxyWriter struct { http.ResponseWriter status int size int } func (r *proxyWriter) Header() http.Header { return r.ResponseWriter.Header() } func (r *proxyWriter) Write(b []byte) (int, error) { if r.status == 0 { // default if WriteHeader has not been called yet r.status = http.StatusOK } size, err := r.ResponseWriter.Write(b) r.size += size return size, err } func (r *proxyWriter) WriteHeader(status int) { r.status = status r.ResponseWriter.WriteHeader(status) } func (r *proxyWriter) Status() int { return r.status } func (r *proxyWriter) Size() int { return r.size }