New Upstream Release - golang-github-shurcool-httpgzip

Ready changes

Summary

Merged new upstream version: 0.0~git20190720.320755c+ds (was: 0.0~git20190516.1c7afaa).

Resulting package

Built on 2022-12-14T03:50 (took 2m26s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-shurcool-httpgzip-dev

Lintian Result

Diff

diff --git a/debian/changelog b/debian/changelog
index 370c39d..f52f56c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-shurcool-httpgzip (0.0~git20190720.320755c+ds-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Wed, 14 Dec 2022 03:48:39 -0000
+
 golang-github-shurcool-httpgzip (0.0~git20190516.1c7afaa-4) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/fs_test.go b/fs_test.go
index 2264ffa..536cf1d 100644
--- a/fs_test.go
+++ b/fs_test.go
@@ -6,7 +6,6 @@ import (
 	"net/http/httptest"
 	"strings"
 	"testing"
-	"time"
 
 	"github.com/shurcooL/httpgzip"
 	"golang.org/x/tools/godoc/vfs/httpfs"
@@ -22,40 +21,11 @@ func ExampleFileServer() {
 	)))
 }
 
-// ServeContent should correctly determine the content type as "text/plain",
-// not as "application/x-gzip".
-func TestServeContent_detectContentType(t *testing.T) {
-	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
-		content := "This is some plain text that compresses easily. " +
-			strings.Repeat("NaN", 16) + " Batman!"
-
-		httpgzip.ServeContent(w, req, "", time.Time{}, strings.NewReader(content))
-	}))
-	defer ts.Close()
-
-	req, err := http.NewRequest("GET", ts.URL, nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-	req.Header.Set("Accept-Encoding", "gzip")
-	resp, err := http.DefaultClient.Do(req)
-	if err != nil {
-		t.Fatal(err)
-	}
-	resp.Body.Close()
-
-	got := resp.Header.Get("Content-Type")
-	want := "text/plain; charset=utf-8"
-	if got != want {
-		t.Errorf("got:\n%v\nwant:\n%v\n", got, want)
-	}
-}
-
 // Test that there are no infinite redirects at root path even if the entire
 // req.URL.Path is stripped, e.g., via an overly aggressive http.StripPrefix.
 // See https://github.com/shurcooL/httpgzip/pull/3
 // and https://github.com/golang/go/commit/3745716bc3940f471137bf06fbe8c042257a43d3.
-func TestFileServer_implicitLeadingSlash(t *testing.T) {
+func TestFileServerImplicitLeadingSlash(t *testing.T) {
 	fs := httpfs.New(mapfs.New(map[string]string{
 		"foo.txt": "Hello world",
 	}))
diff --git a/gzip.go b/gzip.go
index 1bd8a76..cd8ab94 100644
--- a/gzip.go
+++ b/gzip.go
@@ -28,11 +28,18 @@ type NotWorthGzipCompressing interface {
 	NotWorthGzipCompressing()
 }
 
-// ServeContent is like http.ServeContent, except it applies gzip compression.
+// ServeContent is like http.ServeContent, except it applies gzip compression
+// if compression hasn't already been done (i.e., the "Content-Encoding" header is set).
 // It's aware of GzipByter and NotWorthGzipCompressing interfaces, and uses them
 // to improve performance when the provided content implements them. Otherwise,
 // it applies gzip compression on the fly, if it's found to be beneficial.
 func ServeContent(w http.ResponseWriter, req *http.Request, name string, modTime time.Time, content io.ReadSeeker) {
+	// If compression has already been dealt with, serve as is.
+	if _, ok := w.Header()["Content-Encoding"]; ok {
+		http.ServeContent(w, req, name, modTime, content)
+		return
+	}
+
 	// If request doesn't accept gzip encoding, serve without compression.
 	if !httpguts.HeaderValuesContainsToken(req.Header["Accept-Encoding"], "gzip") {
 		http.ServeContent(w, req, name, modTime, content)
diff --git a/gzip_test.go b/gzip_test.go
new file mode 100644
index 0000000..aca9c17
--- /dev/null
+++ b/gzip_test.go
@@ -0,0 +1,70 @@
+package httpgzip_test
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"strings"
+	"testing"
+	"time"
+
+	"github.com/shurcooL/httpgzip"
+)
+
+// Test that ServeContent correctly determines the content type as "text/plain",
+// not as "application/x-gzip".
+func TestServeContentDetectContentType(t *testing.T) {
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+		content := "This is some plain text that compresses easily. " +
+			strings.Repeat("NaN", 16) + " Batman!"
+
+		httpgzip.ServeContent(w, req, "", time.Time{}, strings.NewReader(content))
+	}))
+	defer ts.Close()
+
+	req, err := http.NewRequest("GET", ts.URL, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	req.Header.Set("Accept-Encoding", "gzip")
+	resp, err := http.DefaultClient.Do(req)
+	if err != nil {
+		t.Fatal(err)
+	}
+	resp.Body.Close()
+
+	got := resp.Header.Get("Content-Type")
+	want := "text/plain; charset=utf-8"
+	if got != want {
+		t.Errorf("got:\n%v\nwant:\n%v\n", got, want)
+	}
+}
+
+// Test that if the handler already explicitly set "Content-Encoding" header,
+// then ServeContent shouldn't try to do apply compression, just serve as is.
+func TestServeContentExplicitContentEncoding(t *testing.T) {
+	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+		content := "This is some plain text that compresses easily. " +
+			strings.Repeat("NaN", 16) + " Batman!"
+
+		w.Header()["Content-Encoding"] = nil
+		httpgzip.ServeContent(w, req, "", time.Time{}, strings.NewReader(content))
+	}))
+	defer ts.Close()
+
+	req, err := http.NewRequest("GET", ts.URL, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	req.Header.Set("Accept-Encoding", "gzip")
+	resp, err := http.DefaultClient.Do(req)
+	if err != nil {
+		t.Fatal(err)
+	}
+	resp.Body.Close()
+
+	got := resp.Header.Get("Content-Encoding")
+	want := ""
+	if got != want {
+		t.Errorf("got:\n%q\nwant:\n%q\n", got, want)
+	}
+}

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/shurcooL/httpgzip/gzip_test.go

No differences were encountered in the control files

More details

Full run details