8000 Small optimization · Tomato1107/esp32-snippets@0738301 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0738301

Browse files
committed
Small optimization
1 parent c544fbf commit 0738301
8000

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cpp_utils/WebServer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,12 @@ void WebServer::processRequest(struct mg_connection *mgConnection, struct http_m
557557

558558
// Because we reached here, it means that we did NOT match a handler. Now we want to attempt
559559
// to retrieve the corresponding file content.
560-
std::string filePath = httpResponse.getRootPath();
560+
std::string filePath;
561+
filePath.reserve(httpResponse.getRootPath().length() + message->uri.len + 1);
562+
filePath += httpResponse.getRootPath();
561563
filePath.append(message->uri.p, message->uri.len);
562564
ESP_LOGD(tag, "Opening file: %s", filePath.c_str());
563-
FILE *file = fopen(filePath.c_str(), "r");
565+
FILE *file = fopen(filePath.c_str(), "rb");
564566
if (file != nullptr) {
565567
fseek(file, 0L, SEEK_END);
566568
size_t length = ftell(file);

0 commit comments

Comments
 (0)
0