@@ -738,9 +738,12 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String &path, const char *con
738738 if (download) {
739739 // Extract filename from path and set as download attachment
740740 int filenameStart = path.lastIndexOf (' /' ) + 1 ;
741- char buf[26 + path.length () - filenameStart];
742- char *filename = (char *)path.c_str () + filenameStart;
743- snprintf (buf, sizeof (buf), T_attachment, filename);
741+ const char *filename = path.c_str () + filenameStart;
742+ String buf;
743+ buf.reserve (strlen (T_attachment) + strlen (filename) + 2 );
744+ buf = T_attachment;
745+ buf += filename;
746+ buf += " \" " ;
744747 addHeader (T_Content_Disposition, buf, false );
745748 } else {
746749 // Serve file inline (display in browser)
@@ -764,22 +767,26 @@ AsyncFileResponse::AsyncFileResponse(File content, const String &path, const cha
764767 _content = content;
765768 _contentLength = _content.size ();
766769
767- if (strlen ( contentType) == 0 ) {
770+ if (* contentType == ' \0 ' ) {
768771 _setContentTypeFromPath (path);
769772 } else {
770773 _contentType = contentType;
771774 }
772775
773- int filenameStart = path.lastIndexOf (' /' ) + 1 ;
774- char buf[26 + path.length () - filenameStart];
775- char *filename = (char *)path.c_str () + filenameStart;
776-
777776 if (download) {
778- snprintf_P (buf, sizeof (buf), PSTR (" attachment; filename=\" %s\" " ), filename);
777+ // Extract filename from path and set as download attachment
778+ int filenameStart = path.lastIndexOf (' /' ) + 1 ;
779+ const char *filename = path.c_str () + filenameStart;
780+ String buf;
781+ buf.reserve (strlen (T_attachment) + strlen (filename) + 2 );
782+ buf = T_attachment;
783+ buf += filename;
784+ buf += " \" " ;
785+ addHeader (T_Content_Disposition, buf, false );
779786 } else {
780- snprintf_P (buf, sizeof (buf), PSTR (" inline" ));
787+ // Serve file inline (display in browser)
788+ addHeader (T_Content_Disposition, T_inline, false );
781789 }
782- addHeader (T_Content_Disposition, buf, false );
783790}
784791
785792size_t AsyncFileResponse::_fillBuffer (uint8_t *data, size_t len) {
0 commit comments