Created
January 5, 2015 20:11
-
-
Save lantins/25a7464eb3f2068c22b4 to your computer and use it in GitHub Desktop.
proxy_writer.go
This file contains 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 characters
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment