withcoderesponsewriter.go 521 B

123456789101112131415161718192021222324252627
  1. package security
  2. import "net/http"
  3. type WithCodeResponseWriter struct {
  4. Writer http.ResponseWriter
  5. Code int
  6. }
  7. func (w *WithCodeResponseWriter) Flush() {
  8. if flusher, ok := w.Writer.(http.Flusher); ok {
  9. flusher.Flush()
  10. }
  11. }
  12. func (w *WithCodeResponseWriter) Header() http.Header {
  13. return w.Writer.Header()
  14. }
  15. func (w *WithCodeResponseWriter) Write(bytes []byte) (int, error) {
  16. return w.Writer.Write(bytes)
  17. }
  18. func (w *WithCodeResponseWriter) WriteHeader(code int) {
  19. w.Writer.WriteHeader(code)
  20. w.Code = code
  21. }