Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

on the hosting service, unzip compressed types

Changed files
+47 -1
hosting-service
src
+47 -1
hosting-service/src/server.ts
··· 51 } 52 53 if (meta.encoding === 'gzip' && meta.mimeType) { 54 - // Serve gzipped content with proper headers 55 console.log(`[DEBUG SERVE] ${requestPath}: serving as gzipped with Content-Encoding header`); 56 return new Response(content, { 57 headers: { ··· 154 // Non-HTML files: serve gzipped content as-is with proper headers 155 const content = readFileSync(cachedFile); 156 if (isGzipped) { 157 return new Response(content, { 158 headers: { 159 'Content-Type': mimeType,
··· 51 } 52 53 if (meta.encoding === 'gzip' && meta.mimeType) { 54 + // Don't serve already-compressed media formats with Content-Encoding: gzip 55 + // These formats (video, audio, images) are already compressed and the browser 56 + // can't decode them if we add another layer of compression 57 + const alreadyCompressedTypes = [ 58 + 'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png', 59 + 'image/gif', 'image/webp', 'application/pdf' 60 + ]; 61 + 62 + const isAlreadyCompressed = alreadyCompressedTypes.some(type => 63 + meta.mimeType.toLowerCase().startsWith(type) 64 + ); 65 + 66 + if (isAlreadyCompressed) { 67 + // Decompress the file before serving 68 + console.log(`[DEBUG SERVE] ${requestPath}: decompressing already-compressed media type`); 69 + const { gunzipSync } = await import('zlib'); 70 + const decompressed = gunzipSync(content); 71 + console.log(`[DEBUG SERVE] ${requestPath}: decompressed from ${content.length} to ${decompressed.length} bytes`); 72 + return new Response(decompressed, { 73 + headers: { 74 + 'Content-Type': meta.mimeType, 75 + }, 76 + }); 77 + } 78 + 79 + // Serve gzipped content with proper headers (for HTML, CSS, JS, etc.) 80 console.log(`[DEBUG SERVE] ${requestPath}: serving as gzipped with Content-Encoding header`); 81 return new Response(content, { 82 headers: { ··· 179 // Non-HTML files: serve gzipped content as-is with proper headers 180 const content = readFileSync(cachedFile); 181 if (isGzipped) { 182 + // Don't serve already-compressed media formats with Content-Encoding: gzip 183 + const alreadyCompressedTypes = [ 184 + 'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png', 185 + 'image/gif', 'image/webp', 'application/pdf' 186 + ]; 187 + 188 + const isAlreadyCompressed = alreadyCompressedTypes.some(type => 189 + mimeType.toLowerCase().startsWith(type) 190 + ); 191 + 192 + if (isAlreadyCompressed) { 193 + // Decompress the file before serving 194 + const { gunzipSync } = await import('zlib'); 195 + const decompressed = gunzipSync(content); 196 + return new Response(decompressed, { 197 + headers: { 198 + 'Content-Type': mimeType, 199 + }, 200 + }); 201 + } 202 + 203 return new Response(content, { 204 headers: { 205 'Content-Type': mimeType,