summaryrefslogtreecommitdiff
path: root/pkg/logger/body_writer.go
blob: 60da1515bbc53d6e40df8958f091ecb6755b9ac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package logger

import (
	"bufio"
	"errors"
	"net"
	"net/http"
)

type bodyWriter struct {
	http.ResponseWriter
	status int
}

func newBodyWriter(writer http.ResponseWriter) *bodyWriter {
	return &bodyWriter{
		ResponseWriter: writer,
		status:         http.StatusNotImplemented,
	}
}

// implements http.ResponseWriter
func (w *bodyWriter) Write(b []byte) (int, error) {
	return w.ResponseWriter.Write(b)
}

// implements http.ResponseWriter
func (w *bodyWriter) WriteHeader(code int) {
	w.status = code
	w.ResponseWriter.WriteHeader(code)
}

// implements http.Flusher
func (w *bodyWriter) Flush() {
	if f, ok := w.ResponseWriter.(http.Flusher); ok {
		f.Flush()
	}
}

// implements http.Hijacker
func (w *bodyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
	if hi, ok := w.ResponseWriter.(http.Hijacker); ok {
		return hi.Hijack()
	}
	return nil, nil, errors.New("Hijack not supported")
}