From b9f4d35812a284fb66459845ad6f6793dad89701 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 29 Oct 2025 13:50:09 -0400 Subject: [PATCH] Fix UnicodeDecodeError when viewing compressed datasets When viewing datasets through the gateway, requests would fail with: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 1 The gateway was copying the accept-encoding header from browser requests when proxying to cellxgene backend servers. When accept-encoding is manually set, the Python requests library assumes the caller will handle decompression and leaves response content compressed. The cellxgene server responded with zstd-compressed content (magic bytes 28 b5 2f fd), but the gateway attempted to decode this compressed binary data as UTF-8 text, causing the decode error. Solution: Remove accept-encoding from the copied headers list in cache_entry.py. This allows the requests library to automatically handle compression negotiation and transparently decompress responses (gzip, deflate, brotli, zstd, etc.). This is the standard practice when proxying with requests and maintains all other gateway functionality (URL rewriting, auth, caching, etc.). Tested: - Dataset viewing works with compressed responses - File browser and static assets load correctly - URL rewriting continues to function properly --- cellxgene_gateway/cache_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cellxgene_gateway/cache_entry.py b/cellxgene_gateway/cache_entry.py index 8c72efc..c8dbeef 100644 --- a/cellxgene_gateway/cache_entry.py +++ b/cellxgene_gateway/cache_entry.py @@ -148,7 +148,7 @@ class CacheEntry: headers = {} copy_headers = [ "accept", - "accept-encoding", + # "accept-encoding" - removed: let requests library handle compression/decompression "accept-language", "cache-control", "connection",