Have redbean avoid gzip when emulated without jit

This commit is contained in:
Justine Tunney 2022-12-18 02:22:58 -08:00
parent 5a3c646307
commit 6d39c6f646
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2 changed files with 10 additions and 2 deletions

View file

@ -140,6 +140,7 @@
#define X86_XSAVE 1H, ECX, 26, _X86_CC_XSAVE, _ /* sandybridge c. 2012 */ #define X86_XSAVE 1H, ECX, 26, _X86_CC_XSAVE, _ /* sandybridge c. 2012 */
#define X86_XTPR 1H, ECX, 14, 0, _ #define X86_XTPR 1H, ECX, 14, 0, _
#define X86_ZERO_FCS_FDS 7H, EBX, 13, 0, _ #define X86_ZERO_FCS_FDS 7H, EBX, 13, 0, _
#define X86_JIT 80000001H, ECX, 31, 0, _ /* IsGenuineBlink() */
/* clang-format on */ /* clang-format on */
/* AMD specific features */ /* AMD specific features */

View file

@ -636,6 +636,10 @@ static void DropOutput(void) {
cpm.outbuf = 0; cpm.outbuf = 0;
} }
static bool ShouldAvoidGzip(void) {
return IsGenuineCosmo() || (IsGenuineBlink() && !X86_HAVE(JIT));
}
static char *MergePaths(const char *p, size_t n, const char *q, size_t m, static char *MergePaths(const char *p, size_t n, const char *q, size_t m,
size_t *z) { size_t *z) {
char *r; char *r;
@ -2438,7 +2442,10 @@ static char *CommitOutput(char *p) {
if (!IsTiny() && !IsSslCompressed()) { if (!IsTiny() && !IsSslCompressed()) {
p = stpcpy(p, "Vary: Accept-Encoding\r\n"); p = stpcpy(p, "Vary: Accept-Encoding\r\n");
} }
if (!IsTiny() && !IsSslCompressed() && ClientAcceptsGzip()) { if (!IsTiny() && //
!IsSslCompressed() && //
ClientAcceptsGzip() && //
!ShouldAvoidGzip()) {
cpm.gzipped = outbuflen; cpm.gzipped = outbuflen;
crc = crc32_z(0, cpm.outbuf, outbuflen); crc = crc32_z(0, cpm.outbuf, outbuflen);
WRITE32LE(gzip_footer + 0, crc); WRITE32LE(gzip_footer + 0, crc);
@ -6148,7 +6155,7 @@ static char *ServeAsset(struct Asset *a, const char *path, size_t pathlen) {
return ServeError(500, "Internal Server Error"); return ServeError(500, "Internal Server Error");
} }
} else if (!IsTiny() && cpm.msg.method != kHttpHead && !IsSslCompressed() && } else if (!IsTiny() && cpm.msg.method != kHttpHead && !IsSslCompressed() &&
ClientAcceptsGzip() && ClientAcceptsGzip() && !ShouldAvoidGzip() &&
!(a->file && !(a->file &&
IsNoCompressExt(a->file->path.s, a->file->path.n)) && IsNoCompressExt(a->file->path.s, a->file->path.n)) &&
((cpm.contentlength >= 100 && _startswithi(ct, "text/")) || ((cpm.contentlength >= 100 && _startswithi(ct, "text/")) ||