Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Jan 15, 2021
1 parent 301a741 commit 9d66cc2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"
)

// LoggedMux is an http.Server implementation which multiplexes requests to the
// vhost backends and logs each request.
type LoggedMux struct {
*http.ServeMux
VhostLogListeners map[string]chan string
Expand Down Expand Up @@ -56,23 +58,28 @@ func getHostName(input string) string {
return s[0]
}

// LogRecord is a thin wrapper around http.ResponseWriter which allows us to
// capture the number of response bytes written and the http status code.
type LogRecord struct {
http.ResponseWriter
status int
responseBytes int64
}

// Write wrapper that counts bytes
func (r *LogRecord) Write(p []byte) (int, error) {
written, err := r.ResponseWriter.Write(p)
r.responseBytes += int64(written)
return written, err
}

// WriteHeader wrapper that captures status code
func (r *LogRecord) WriteHeader(status int) {
r.status = status
r.ResponseWriter.WriteHeader(status)
}

// Hijack wrapper
func (r *LogRecord) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err error) {
hj, ok := r.ResponseWriter.(http.Hijacker)
if !ok {
Expand Down

0 comments on commit 9d66cc2

Please sign in to comment.