@@ -503,39 +503,16 @@ void AsyncFileResponse::_setContentType(const String& path){
503
503
else _contentType = F (" text/plain" );
504
504
}
505
505
506
- AsyncFileResponse::AsyncFileResponse (FS &fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback): AsyncAbstractResponse(callback){
507
- _code = 200 ;
508
- _path = path;
509
-
510
- if (!download && !fs.exists (_path) && fs.exists (_path+" .gz" )){
511
- _path = _path+" .gz" ;
512
- addHeader (F (" Content-Encoding" ), F (" gzip" ));
513
- _callback = nullptr ; // Unable to process zipped templates
514
- _sendContentLength = true ;
515
- _chunked = false ;
506
+ static File fs_open_zipped (FS& fs, const String& path, bool force_absolute) {
507
+ if (!force_absolute && !fs.exists (path)) {
508
+ auto gz_path = path + F (" .gz" );
509
+ if (fs.exists (gz_path)) return fs.open (gz_path, " r" );
516
510
}
511
+ return fs.open (path, " r" );
512
+ };
517
513
518
- _content = fs.open (_path, " r" );
519
- _contentLength = _content.size ();
520
-
521
- if (contentType == " " )
522
- _setContentType (path);
523
- else
524
- _contentType = contentType;
525
-
526
- int filenameStart = path.lastIndexOf (' /' ) + 1 ;
527
- char buf[26 +path.length ()-filenameStart];
528
- char * filename = (char *)path.c_str () + filenameStart;
529
-
530
- if (download) {
531
- // set filename and force download
532
- snprintf_P (buf, sizeof (buf), PSTR (" attachment; filename=\" %s\" " ), filename);
533
- } else {
534
- // force rendering
535
- snprintf_P (buf, sizeof (buf), PSTR (" inline" ));
536
- }
537
- addHeader (F (" Content-Disposition" ), buf);
538
- }
514
+ AsyncFileResponse::AsyncFileResponse (FS &fs, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback)
515
+ : AsyncFileResponse(fs_open_zipped(fs, path, download), path, contentType, download, callback) {};
539
516
540
517
AsyncFileResponse::AsyncFileResponse (File content, const String& path, const String& contentType, bool download, AwsTemplateProcessor callback): AsyncAbstractResponse(callback){
541
518
_code = 200 ;
@@ -551,7 +528,7 @@ AsyncFileResponse::AsyncFileResponse(File content, const String& path, const Str
551
528
_content = content;
552
529
_contentLength = _content.size ();
553
530
554
- if (contentType == " " )
531
+ if (contentType. length () == 0 )
555
532
_setContentType (path);
556
533
else
557
534
_contentType = contentType;
0 commit comments