6
6
7
7
using namespace asyncsrv ;
8
8
9
- // Since ESP8266 does not link memchr by default, here's its implementation.
10
- void *memchr (void *ptr, int ch, size_t count) {
11
- unsigned char *p = static_cast <unsigned char *>(ptr);
12
- while (count--) {
13
- if (*p++ == static_cast <unsigned char >(ch)) {
14
- return --p;
15
- }
16
- }
17
- return nullptr ;
18
- }
19
-
20
9
/*
21
10
* Abstract Response
22
11
*
@@ -642,7 +631,7 @@ void AsyncFileResponse::_setContentTypeFromPath(const String &path) {
642
631
const char *dot = strrchr (cpath, ' .' );
643
632
644
633
if (!dot) {
645
- _contentType = T_text_plain ;
634
+ _contentType = T_application_octet_stream ;
646
635
return ;
647
636
}
648
637
@@ -674,20 +663,20 @@ void AsyncFileResponse::_setContentTypeFromPath(const String &path) {
674
663
_contentType = T_font_woff;
675
664
} else if (strcmp (dot, T__ttf) == 0 ) {
676
665
_contentType = T_font_ttf;
677
- } else if (strcmp (dot, T__eot) == 0 ) {
678
- _contentType = T_font_eot;
679
666
} else if (strcmp (dot, T__xml) == 0 ) {
680
667
_contentType = T_text_xml;
681
668
} else if (strcmp (dot, T__pdf) == 0 ) {
682
669
_contentType = T_application_pdf;
683
670
} else if (strcmp (dot, T__mp4) == 0 ) {
684
671
_contentType = T_video_mp4;
685
- } else if (strcmp (dot, T__zip ) == 0 ) {
686
- _contentType = T_application_zip ;
687
- } else if (strcmp (dot, T__gz ) == 0 ) {
688
- _contentType = T_application_x_gzip ;
689
- } else {
672
+ } else if (strcmp (dot, T__opus ) == 0 ) {
673
+ _contentType = T_audio_opus ;
674
+ } else if (strcmp (dot, T__webm ) == 0 ) {
675
+ _contentType = T_video_webm ;
676
+ } else if ( strcmp (dot, T__txt) == 0 ) {
690
677
_contentType = T_text_plain;
678
+ } else {
679
+ _contentType = T_application_octet_stream;
691
680
}
692
681
#endif
693
682
}
@@ -707,14 +696,17 @@ void AsyncFileResponse::_setContentTypeFromPath(const String &path) {
707
696
*/
708
697
AsyncFileResponse::AsyncFileResponse (FS &fs, const String &path, const char *contentType, bool download, AwsTemplateProcessor callback)
709
698
: AsyncAbstractResponse(callback) {
699
+
710
700
// Try to open the uncompressed version first
711
701
_content = fs.open (path, fs::FileOpenMode::read);
712
- if (_content.available ()) {
713
- _path = path;
714
- } else {
715
- // Try to open the compressed version (.gz)
716
- _path = path + asyncsrv::T__gz;
717
- _content = fs.open (_path, fs::FileOpenMode::read);
702
+ if (!_content.available ()) {
703
+ // If not available try to open the compressed version (.gz)
704
+ String gzPath;
705
+ uint16_t pathLen = path.length ();
706
+ gzPath.reserve (pathLen + 3 );
707
+ gzPath.concat (path);
708
+ gzPath.concat (asyncsrv::T__gz);
709
+ _content = fs.open (gzPath, fs::FileOpenMode::read);
718
710
719
711
char serverETag[9 ];
720
712
if (AsyncWebServerRequest::_getEtag (_content, serverETag)) {
@@ -761,9 +753,8 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String &path, const char *con
761
753
AsyncFileResponse::AsyncFileResponse (File content, const String &path, const char *contentType, bool download, AwsTemplateProcessor callback)
762
754
: AsyncAbstractResponse(callback) {
763
755
_code = 200 ;
764
- _path = path;
765
756
766
- if (!download && String (content.name ()).endsWith (T__gz) && !path.endsWith (T__gz)) {
757
+ if (String (content.name ()).endsWith (T__gz) && !path.endsWith (T__gz)) {
767
758
addHeader (T_Content_Encoding, T_gzip, false );
768
759
_callback = nullptr ; // Unable to process gzipped templates
769
760
_sendContentLength = true ;
0 commit comments