323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
323
324
325
326
327
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
|
-
+
+
+
+
+
-
+
+
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
|
}else{
blob_appendf(&extraHeader,
"Set-Cookie: %s=%t; Path=%s; HttpOnly; %s\r\n",
zName, zValue, zPath, zSecure);
}
}
/*
** Values for use with is_compressible().
*/
#define COMPRESSIBLE_ZLIB 1
#define COMPRESSIBLE_BROTLI 2
/*
** Return true if the response should be sent with Content-Encoding: gzip.
** Return true if the response should be sent with Content-Encoding: X, where
** X corresponds to the type argument (one of the COMPRESSIBLE_xyz macros).
*/
static int is_gzippable(void){
static int is_compressible(int type){
if( g.fNoHttpCompress ) return 0;
switch( type ){
case COMPRESSIBLE_ZLIB:
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
break;
case COMPRESSIBLE_BROTLI:
#ifdef HAVE_BROTLIENCODERCOMPRESS
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "br")==0 ) return 0;
break;
#else
return 0;
#endif
default:
break;
}
/* 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==fossil_strncmp("application/",zContentType,12)){
const char * z = &zContentType[12];
|
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
|
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
|
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
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;
gzip_begin(0);
for( i=0; i<2; i++ ){
int size = blob_size(&cgiContent[i]);
if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size);
blob_reset(&cgiContent[i]);
}
gzip_finish(&cgiContent[0]);
blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
if( iReplyStatus!=206 ){
if( is_compressible(COMPRESSIBLE_ZLIB) ){
int i;
gzip_begin(0);
for( i=0; i<2; i++ ){
int size = blob_size(&cgiContent[i]);
if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size);
blob_reset(&cgiContent[i]);
}
gzip_finish(&cgiContent[0]);
blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
}
#ifdef HAVE_BROTLIENCODERCOMPRESS
else if( is_compressible(COMPRESSIBLE_BROTLI) ){
/* TODO */
}
#endif
}
total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
if( iReplyStatus==206 ){
blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
rangeStart, rangeEnd-1, total_size);
total_size = rangeEnd - rangeStart;
}
|