Skip to content

Commit 291bc6b

Browse files
Wrap mimetype strings in FSPTR()s (#4338)
Mimetype is now in progmem, so any accesses to it need to be using FPSTR() wrapped Strings. Fixes #4329
1 parent bf5a0f2 commit 291bc6b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool ESP8266WebServer::authenticate(const char * username, const char * password
195195
#endif
196196
md5.begin();
197197
if(authReq.indexOf(FPSTR(qop_auth)) != -1) {
198-
md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _nc + FPSTR(colon) + _cnonce + ':auth:' + _H2);
198+
md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _nc + FPSTR(colon) + _cnonce + ":auth:" + _H2);
199199
}else{
200200
md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _H2);
201201
}
@@ -376,7 +376,7 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
376376
if (!content_type)
377377
content_type = mimeTable[html].mimeType;
378378

379-
sendHeader(String(F("Content-Type")), content_type, true);
379+
sendHeader(String(F("Content-Type")), String(FPSTR(content_type)), true);
380380
if (_contentLength == CONTENT_LENGTH_NOT_SET) {
381381
sendHeader(String(FPSTR(Content_Length)), String(contentLength));
382382
} else if (_contentLength != CONTENT_LENGTH_UNKNOWN) {
@@ -485,9 +485,9 @@ void ESP8266WebServer::_streamFileCore(const size_t fileSize, const String & fil
485485
{
486486
using namespace mime;
487487
setContentLength(fileSize);
488-
if (fileName.endsWith(mimeTable[gz].endsWith) &&
489-
contentType != mimeTable[gz].mimeType &&
490-
contentType != mimeTable[none].mimeType) {
488+
if (fileName.endsWith(String(FPSTR(mimeTable[gz].endsWith))) &&
489+
contentType != String(FPSTR(mimeTable[gz].mimeType)) &&
490+
contentType != String(FPSTR(mimeTable[none].mimeType))) {
491491
sendHeader(F("Content-Encoding"), F("gzip"));
492492
}
493493
send(200, contentType, "");

libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "RequestHandler.h"
55
#include "mimetable.h"
6+
#include "WString.h"
67

78
using namespace mime;
89

@@ -101,10 +102,10 @@ class StaticRequestHandler : public RequestHandler {
101102

102103
// look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for
103104
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
104-
if (!path.endsWith(mimeTable[gz].endsWith) && !_fs.exists(path)) {
105-
String pathWithGz = path + mimeTable[gz].endsWith;
105+
if (!path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !_fs.exists(path)) {
106+
String pathWithGz = path + FPSTR(mimeTable[gz].endsWith);
106107
if(_fs.exists(pathWithGz))
107-
path += mimeTable[gz].endsWith;
108+
path += FPSTR(mimeTable[gz].endsWith);
108109
}
109110

110111
File f = _fs.open(path, "r");

0 commit comments

Comments
 (0)