High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(download): improve gzip detection and e2e test reliability
Data0417f65e63ae
diff --git a/internal/handlers/download.go b/internal/handlers/download.goindex 6565ae7a..4a7a0686 100644--- a/internal/handlers/download.go+++ b/internal/handlers/download.go@@ -11,6 +11,7 @@ import ("net/http""net/url""os"+ "path""path/filepath""strconv""strings"@@ -654,7 +655,12 @@ func isGzipContent(contentType, rawURL string) bool {if strings.Contains(strings.ToLower(contentType), "gzip") {return true}- return strings.HasSuffix(strings.ToLower(rawURL), ".gz")+ // Use path.Ext for precise extension matching (.gz, not .pgz or .ngz)+ parsed, err := url.Parse(rawURL)+ if err != nil {+ return false+ }+ return strings.EqualFold(path.Ext(parsed.Path), ".gz")}func inferDecompressedContentType(rawURL, fallback string) string {diff --git a/internal/handlers/download_fallback_test.go b/internal/handlers/download_fallback_test.goindex 0f133f70..41b24985 100644--- a/internal/handlers/download_fallback_test.go+++ b/internal/handlers/download_fallback_test.go@@ -21,6 +21,13 @@ func TestIsGzipContent(t *testing.T) {{"application/xml", "https://example.com/sitemap.xml", false},{"text/html", "https://example.com/page", false},{"", "https://example.com/data.gz", true},+ // Edge cases: path.Ext should not match these as .gz+ {"", "https://example.com/file.pgz", false},+ {"", "https://example.com/file.ngz", false},+ {"", "https://example.com/filegz", false},+ // Query params should not affect extension detection+ {"", "https://example.com/data.gz?token=abc", true},+ {"", "https://example.com/data.tar.gz", true},}for _, tt := range tests {if got := isGzipContent(tt.contentType, tt.url); got != tt.want {diff --git a/tests/e2e/scenarios-cli/files-full.sh b/tests/e2e/scenarios-cli/files-full.shindex 72772dbf..dd225578 100644--- a/tests/e2e/scenarios-cli/files-full.sh+++ b/tests/e2e/scenarios-cli/files-full.sh@@ -79,10 +79,16 @@ if [ -f "$GZ_FIXTURE" ]; thenpython3 -m http.server 0 --directory "$GZ_DIR" --bind 0.0.0.0 &>/tmp/e2e-gz-server.log &GZ_PID=$!- sleep 1- # Extract the port from the log- GZ_PORT=$(grep -oE 'port [0-9]+' /tmp/e2e-gz-server.log | head -1 | grep -oE '[0-9]+')+ # Poll for server startup with timeout (handles slow CI)+ GZ_PORT=""+ for i in {1..10}; do+ GZ_PORT=$(grep -oE 'port [0-9]+' /tmp/e2e-gz-server.log 2>/dev/null | head -1 | grep -oE '[0-9]+' || true)+ if [ -n "$GZ_PORT" ] && [ "$GZ_PORT" != "0" ]; then+ break+ fi+ sleep 0.5+ doneif [ -n "$GZ_PORT" ] && [ "$GZ_PORT" != "0" ]; then# The server binds 0.0.0.0, access via the host the pinchtab instance can reach.