Fossil

Check-in [86db2d94]
Login

Check-in [86db2d94]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Based on discussions in forum thread f60dece061c364d1, (A) re-add the charset=utf-8 for text/* mimetypes, (B) extend the set of gzip-compressible mimetypes (e.g. JSON, wasm, tcl, tar), and (C) refactor (B)'s impl so that adding new types does not add a performance hit (it's faster now for most mimetypes).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pikchrshow-wasm
Files: files | file ages | folders
SHA3-256: 86db2d94c60e23845362e5793280583223405f79c505f834c8aa13a60db9d9c5
User & Date: stephan 2022-06-08 07:36:05
Context
2022-06-08
07:54
Added mimetype image/vnd.microsoft.icon to the is-compressible list, per forum feedback. Consolidated strncmp() vs fossil_strncmp() into fossil_strncmp() in cgi.c for consistency's sake. ... (check-in: 3652b4d6 user: stephan tags: pikchrshow-wasm)
07:36
Based on discussions in forum thread f60dece061c364d1, (A) re-add the charset=utf-8 for text/* mimetypes, (B) extend the set of gzip-compressible mimetypes (e.g. JSON, wasm, tcl, tar), and (C) refactor (B)'s impl so that adding new types does not add a performance hit (it's faster now for most mimetypes). ... (check-in: 86db2d94 user: stephan tags: pikchrshow-wasm)
02:42
Removed the unused/incomplete split-view widget. The current UI doesn't seem to need that level of manual size tuning. ... (check-in: ba1be566 user: stephan tags: pikchrshow-wasm)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/cgi.c.

328
329
330
331
332
333
334



335

336










337









338
339
340
341
342
343
344

/*
** Return true if the response should be sent with Content-Encoding: gzip.
*/
static int is_gzippable(void){
  if( g.fNoHttpCompress ) return 0;
  if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;



  return strncmp(zContentType, "text/", 5)==0

    || sqlite3_strglob("application/*xml", zContentType)==0










    || sqlite3_strglob("application/*javascript", zContentType)==0;









}


/*
** The following routines read or write content from/to the wire for
** an HTTP request.  Depending on settings the content might be coming
** from or going to a socket, or a file, or it might come from or go







>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

/*
** Return true if the response should be sent with Content-Encoding: gzip.
*/
static int is_gzippable(void){
  if( g.fNoHttpCompress ) return 0;
  if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
  /* Maintenance note: this oddball structure is intended to make
  ** adding new mimetypes to this list less of a performance hit than
  ** doing a strcmp/glob over a growing set of compressible types. */
  switch(zContentType ? *zContentType : 0){
    case (int)'a':
      if(0==strncmp("application/",zContentType,12)){
        const char * z = &zContentType[12];
        switch(*z){
          case (int)'j':
            return fossil_strcmp("javascript", z)==0
                || fossil_strcmp("json", z)==0;
          case (int)'w': return fossil_strcmp("wasm", z)==0;
          case (int)'x':
            return fossil_strcmp("x-tcl", z)==0
                || fossil_strcmp("x-tar", z)==0;
          default:
            return sqlite3_strglob("*xml", z)==0;
        }
      }
      break;
    case (int)'i':
      return fossil_strcmp(zContentType, "image/svg+xml")==0;
    case (int)'t':
      return fossil_strncmp(zContentType, "text/", 5)==0;
  }
  return 0;
}


/*
** The following routines read or write content from/to the wire for
** an HTTP request.  Depending on settings the content might be coming
** from or going to a socket, or a file, or it might come from or go
417
418
419
420
421
422
423



















424
425
426
427
428
429
430
*/
static void cgi_fflush(void){
  if( !g.httpUseSSL ){
    fflush(g.httpOut);
  }
}





















/*
** Generate the reply to a web request.  The output might be an
** full HTTP response, or a CGI response, depending on how things have
** be set up.
**
** The reply consists of a response header (an HTTP or CGI response header)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
*/
static void cgi_fflush(void){
  if( !g.httpUseSSL ){
    fflush(g.httpOut);
  }
}

/*
** Given a Content-Type value, returns a string suitable for appending
** to the Content-Type header for adding (or not) the "; charset=..."
** part. It returns an empty string for most types or if zContentType
** is NULL.
**
** See forum post f60dece061c364d1 for the discussions which lead to
** this. Previously we always appended the charset, but WASM loaders
** are pedantic and refuse to load any responses which have a
** charset. Also, adding a charset is not strictly appropriate for
** most types (and not required for many others which may ostensibly
** benefit from one, as detailed in that forum post).
*/
static const char * content_type_charset(const char *zContentType){
  if(zContentType!=0){
    if(0==strncmp(zContentType,"text/",5)) return "; charset=utf-8";
  }
  return "";
}

/*
** Generate the reply to a web request.  The output might be an
** full HTTP response, or a CGI response, depending on how things have
** be set up.
**
** The reply consists of a response header (an HTTP or CGI response header)
491
492
493
494
495
496
497
498

499
500
501
502
503
504
505
  ** a CGI script.
  */

  /* Content intended for logged in users should only be cached in
  ** the browser, not some shared location.
  */
  if( iReplyStatus!=304 ) {
    blob_appendf(&hdr, "Content-Type: %s\r\n", zContentType);

    if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
      cgi_combine_header_and_body();
      blob_compress(&cgiContent[0], &cgiContent[0]);
    }

    if( is_gzippable() && iReplyStatus!=206 ){
      int i;







|
>







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  ** a CGI script.
  */

  /* Content intended for logged in users should only be cached in
  ** the browser, not some shared location.
  */
  if( iReplyStatus!=304 ) {
    blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
                 content_type_charset(zContentType));
    if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
      cgi_combine_header_and_body();
      blob_compress(&cgiContent[0], &cgiContent[0]);
    }

    if( is_gzippable() && iReplyStatus!=206 ){
      int i;