|
|
@ -1,10 +1,12 @@
|
|
|
|
package handler
|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httputil"
|
|
|
|
"net/http/httputil"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
@ -25,10 +27,22 @@ type loggedResponseWriter struct {
|
|
|
|
code int
|
|
|
|
code int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (w *loggedResponseWriter) Flush() {
|
|
|
|
|
|
|
|
if flusher, ok := w.w.(http.Flusher); ok {
|
|
|
|
|
|
|
|
flusher.Flush()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (w *loggedResponseWriter) Header() http.Header {
|
|
|
|
func (w *loggedResponseWriter) Header() http.Header {
|
|
|
|
return w.w.Header()
|
|
|
|
return w.w.Header()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hijack implements the http.Hijacker interface.
|
|
|
|
|
|
|
|
// This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.
|
|
|
|
|
|
|
|
func (w *loggedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|
|
|
|
|
|
|
return w.w.(http.Hijacker).Hijack()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (w *loggedResponseWriter) Write(bytes []byte) (int, error) {
|
|
|
|
func (w *loggedResponseWriter) Write(bytes []byte) (int, error) {
|
|
|
|
return w.w.Write(bytes)
|
|
|
|
return w.w.Write(bytes)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -38,12 +52,6 @@ func (w *loggedResponseWriter) WriteHeader(code int) {
|
|
|
|
w.code = code
|
|
|
|
w.code = code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (w *loggedResponseWriter) Flush() {
|
|
|
|
|
|
|
|
if flusher, ok := w.w.(http.Flusher); ok {
|
|
|
|
|
|
|
|
flusher.Flush()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LogHandler returns a middleware that logs http request and response.
|
|
|
|
// LogHandler returns a middleware that logs http request and response.
|
|
|
|
func LogHandler(next http.Handler) http.Handler {
|
|
|
|
func LogHandler(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|