Skip to content

Commit 42d2aad

Browse files
authored
Merge pull request #228 from JosePineiro/fix/send-content-type
Fix bug. Sometimes the content type isn't sent.
2 parents 35ee69e + c19a64c commit 42d2aad

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/AsyncWebServerRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void AsyncWebServerRequest::send(FS &fs, const String &path, const char *content
2727

2828
// Handle compressed version
2929
const String gzPath = path + asyncsrv::T__gz;
30-
File gzFile = fs.open(gzPath, "r");
30+
File gzFile = fs.open(gzPath, fs::FileOpenMode::read);
3131

3232
// Compressed file not found or invalid
3333
if (!gzFile.seek(gzFile.size() - 8)) {

src/WebResponses.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String &path, const char *con
734734
}
735735
}
736736

737-
if (*contentType != '\0') {
737+
if (*contentType == '\0') {
738738
_setContentTypeFromPath(path);
739739
} else {
740740
_contentType = contentType;
@@ -745,11 +745,11 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, const String &path, const char *con
745745
int filenameStart = path.lastIndexOf('/') + 1;
746746
char buf[26 + path.length() - filenameStart];
747747
char *filename = (char *)path.c_str() + filenameStart;
748-
snprintf_P(buf, sizeof(buf), PSTR("attachment; filename=\"%s\""), filename);
748+
snprintf(buf, sizeof(buf), T_attachment, filename);
749749
addHeader(T_Content_Disposition, buf, false);
750750
} else {
751751
// Serve file inline (display in browser)
752-
addHeader(T_Content_Disposition, PSTR("inline"), false);
752+
addHeader(T_Content_Disposition, T_inline, false);
753753
}
754754

755755
_code = 200;

src/literals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace asyncsrv {
77

88
static constexpr const char *empty = "";
99

10+
static constexpr const char *T_inline = "inline";
11+
static constexpr const char *T_attachment = "attachment; filename=\"%s\"";
12+
1013
static constexpr const char *T__opaque = "\", opaque=\"";
1114
static constexpr const char *T_100_CONTINUE = "100-continue";
1215
static constexpr const char *T_13 = "13";

0 commit comments

Comments
 (0)