mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
swarm/api: wrapping the responseWriter
This commit is contained in:
parent
719da647d8
commit
6a2b73eae5
1 changed files with 21 additions and 2 deletions
|
|
@ -799,10 +799,13 @@ func (s *Server) HandleGetFile(w http.ResponseWriter, r *Request) {
|
|||
http.ServeContent(w, &r.Request, "", time.Now(), reader)
|
||||
}
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
req := &Request{Request: *r, ruid: uuid.New()[:8]}
|
||||
requestCount.Inc(1)
|
||||
log.Info("serve request", "ruid", req.ruid, "method", r.Method, "url", r.RequestURI)
|
||||
log.Info("serving request", "ruid", req.ruid, "method", r.Method, "url", r.RequestURI)
|
||||
|
||||
// wrapping the ResponseWriter, so that we get the response code set by http.ServeContent
|
||||
w := newLoggingResponseWriter(rw)
|
||||
|
||||
if r.RequestURI == "/" && strings.Contains(r.Header.Get("Accept"), "text/html") {
|
||||
|
||||
|
|
@ -880,6 +883,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
default:
|
||||
Respond(w, req, fmt.Sprintf("%s method is not supported", r.Method), http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
log.Info("served response", "ruid", req.ruid, "code", w.statusCode)
|
||||
}
|
||||
|
||||
func (s *Server) updateManifest(key storage.Key, update func(mw *api.ManifestWriter) error) (storage.Key, error) {
|
||||
|
|
@ -899,3 +904,17 @@ func (s *Server) updateManifest(key storage.Key, update func(mw *api.ManifestWri
|
|||
log.Debug(fmt.Sprintf("generated manifest %s", key))
|
||||
return key, nil
|
||||
}
|
||||
|
||||
type loggingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func newLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
|
||||
return &loggingResponseWriter{w, http.StatusOK}
|
||||
}
|
||||
|
||||
func (lrw *loggingResponseWriter) WriteHeader(code int) {
|
||||
lrw.statusCode = code
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue