grim/hgkeeper

rename responseWrite to cachingResponseWriter
draft
5 months ago, Gary Kramlich
4fc4d4c7aac6
Parents 410414a1fbe7
Children 32762318fbdd
rename responseWrite to cachingResponseWriter
--- a/hgweb/cache.go Wed Apr 15 00:48:00 2020 -0500
+++ b/hgweb/cache.go Wed Apr 15 00:53:36 2020 -0500
@@ -62,7 +62,7 @@
// who will validate the etag if specified, or just do the work.
// create our response writer which caches the data
- rw := newResponseWriter(w)
+ rw := newCachingResponseWriter(w)
// send the request to mercurial
next.ServeHTTP(rw, r)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hgweb/cachingresponsewriter.go Wed Apr 15 00:53:36 2020 -0500
@@ -0,0 +1,68 @@
+package hgweb
+
+import (
+ "bytes"
+ "io"
+ "net/http"
+)
+
+type cachingResponseWriter struct {
+ w http.ResponseWriter
+ wroteHeader bool
+ statusCode int
+ written int64
+
+ multiWriter io.Writer
+ cachedBody *bytes.Buffer
+}
+
+var _ http.ResponseWriter = (*cachingResponseWriter)(nil)
+
+func newCachingResponseWriter(w http.ResponseWriter) *cachingResponseWriter {
+ rw := &cachingResponseWriter{
+ w: w,
+ cachedBody: &bytes.Buffer{},
+ }
+
+ rw.multiWriter = io.MultiWriter(w, rw.cachedBody)
+
+ return rw
+}
+
+func (w *cachingResponseWriter) Header() http.Header {
+ return w.w.Header()
+}
+
+func (w *cachingResponseWriter) Write(data []byte) (int, error) {
+ if !w.wroteHeader {
+ w.wroteHeader = true
+ w.statusCode = http.StatusOK
+ }
+
+ l, err := w.multiWriter.Write(data)
+ w.written += int64(l)
+
+ return l, err
+}
+
+func (w *cachingResponseWriter) WriteHeader(statusCode int) {
+ if !w.wroteHeader {
+ w.wroteHeader = true
+
+ w.statusCode = statusCode
+ }
+
+ w.w.WriteHeader(w.statusCode)
+}
+
+func (w *cachingResponseWriter) StatusCode() int {
+ return w.statusCode
+}
+
+func (w *cachingResponseWriter) Written() int64 {
+ return w.written
+}
+
+func (w *cachingResponseWriter) Body() []byte {
+ return w.cachedBody.Bytes()
+}
--- a/hgweb/responsewriter.go Wed Apr 15 00:48:00 2020 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-package hgweb
-
-import (
- "bytes"
- "io"
- "net/http"
-)
-
-type responseWriter struct {
- w http.ResponseWriter
- wroteHeader bool
- statusCode int
- written int64
-
- multiWriter io.Writer
- cachedBody *bytes.Buffer
-}
-
-var _ http.ResponseWriter = (*responseWriter)(nil)
-
-func newResponseWriter(w http.ResponseWriter) *responseWriter {
- rw := &responseWriter{
- w: w,
- cachedBody: &bytes.Buffer{},
- }
-
- rw.multiWriter = io.MultiWriter(w, rw.cachedBody)
-
- return rw
-}
-
-func (w *responseWriter) Header() http.Header {
- return w.w.Header()
-}
-
-func (w *responseWriter) Write(data []byte) (int, error) {
- if !w.wroteHeader {
- w.wroteHeader = true
- w.statusCode = http.StatusOK
- }
-
- l, err := w.multiWriter.Write(data)
- w.written += int64(l)
-
- return l, err
-}
-
-func (w *responseWriter) WriteHeader(statusCode int) {
- if !w.wroteHeader {
- w.wroteHeader = true
-
- w.statusCode = statusCode
- }
-
- w.w.WriteHeader(w.statusCode)
-}
-
-func (w *responseWriter) StatusCode() int {
- return w.statusCode
-}
-
-func (w *responseWriter) Written() int64 {
- return w.written
-}
-
-func (w *responseWriter) Body() []byte {
- return w.cachedBody.Bytes()
-}