aboutsummaryrefslogtreecommitdiffstats
path: root/web/web_test.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 14:22:50 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 14:22:50 -0800
commit97150dcd533fc9552c95ffc5ba912e3a4d2eb506 (patch)
tree288af69fd86611a19daef100213a396b7d2f9fc2 /web/web_test.go
parente014ded82a630bd91b15be4307125f5580119f4d (diff)
downloadneko-97150dcd533fc9552c95ffc5ba912e3a4d2eb506.tar.gz
neko-97150dcd533fc9552c95ffc5ba912e3a4d2eb506.tar.bz2
neko-97150dcd533fc9552c95ffc5ba912e3a4d2eb506.zip
Implement robust Gzip middleware and update page size analysis
Diffstat (limited to 'web/web_test.go')
-rw-r--r--web/web_test.go52
1 files changed, 47 insertions, 5 deletions
diff --git a/web/web_test.go b/web/web_test.go
index 9030947..039ad89 100644
--- a/web/web_test.go
+++ b/web/web_test.go
@@ -422,13 +422,55 @@ func TestServeFrontend(t *testing.T) {
// We expect 200 if built, or maybe panic if box not found (rice.MustFindBox)
// But rice usually works in dev mode by looking at disk.
if rr.Code != http.StatusOK {
- // If 404/500, it might be that dist is missing, but for this specific verification
+ // If 404/500, it might be that dist is missing, but for this specific verification
// where we know we built it, we expect 200.
// However, protecting against CI failures where build might not happen:
t.Logf("Got code %d for frontend request", rr.Code)
}
- // Check for unauthenticated access (no cookie needed)
- if rr.Code == http.StatusTemporaryRedirect {
- t.Error("Frontend should not redirect to login")
- }
+ // Check for unauthenticated access (no cookie needed)
+ if rr.Code == http.StatusTemporaryRedirect {
+ t.Error("Frontend should not redirect to login")
+ }
+}
+
+func TestGzipCompression(t *testing.T) {
+ handler := GzipMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/plain")
+ w.Write([]byte("this is a test string that should be compressed when gzip is enabled and the client supports it"))
+ }))
+
+ // Case 1: Client supports gzip
+ req := httptest.NewRequest("GET", "/", nil)
+ req.Header.Set("Accept-Encoding", "gzip")
+ rr := httptest.NewRecorder()
+ handler.ServeHTTP(rr, req)
+
+ if rr.Header().Get("Content-Encoding") != "gzip" {
+ t.Errorf("Expected Content-Encoding: gzip, got %q", rr.Header().Get("Content-Encoding"))
+ }
+
+ // Case 2: Client does NOT support gzip
+ req = httptest.NewRequest("GET", "/", nil)
+ rr = httptest.NewRecorder()
+ handler.ServeHTTP(rr, req)
+
+ if rr.Header().Get("Content-Encoding") == "gzip" {
+ t.Error("Expected no Content-Encoding: gzip for client without support")
+ }
+
+ // Case 3: 304 Not Modified (Should NOT be gzipped)
+ handler304 := GzipMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusNotModified)
+ }))
+ req = httptest.NewRequest("GET", "/", nil)
+ req.Header.Set("Accept-Encoding", "gzip")
+ rr = httptest.NewRecorder()
+ handler304.ServeHTTP(rr, req)
+
+ if rr.Code != http.StatusNotModified {
+ t.Errorf("Expected 304, got %d", rr.Code)
+ }
+ if rr.Header().Get("Content-Encoding") == "gzip" {
+ t.Error("Expected no Content-Encoding for 304 response")
+ }
}