Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 84f4572

Browse files
vortigontmathieucarbou
authored andcommitted
rollback time handling code style from c++ to C and 8266
1 parent 52c0db9 commit 84f4572

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/WebHandlerImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include "stddef.h"
3030
#include <time.h>
31-
#include <ctime>
3231

3332
class AsyncStaticWebHandler: public AsyncWebHandler {
3433
using File = fs::File;
@@ -56,7 +55,7 @@ class AsyncStaticWebHandler: public AsyncWebHandler {
5655
AsyncStaticWebHandler& setDefaultFile(const char* filename);
5756
AsyncStaticWebHandler& setCacheControl(const char* cache_control);
5857
AsyncStaticWebHandler& setLastModified(const char* last_modified);
59-
AsyncStaticWebHandler& setLastModified(const std::tm* last_modified);
58+
AsyncStaticWebHandler& setLastModified(struct tm* last_modified);
6059
#ifdef ESP8266
6160
AsyncStaticWebHandler& setLastModified(time_t last_modified);
6261
AsyncStaticWebHandler& setLastModified(); //sets to current time. Make sure sntp is runing and time is updated

src/WebHandlers.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const char* last_m
6262
return *this;
6363
}
6464

65-
AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const std::tm* last_modified){
66-
constexpr size_t buffsize = sizeof("Fri, 27 Jan 2023 15:50:27 GMT"); // a format for LM header
67-
char result[buffsize];
68-
std::strftime(result, buffsize, "%a, %d %b %Y %H:%M:%S GMT", last_modified);
69-
return setLastModified(static_cast<const char *>(result));
65+
AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(struct tm* last_modified){
66+
auto formatP = PSTR("%a, %d %b %Y %H:%M:%S %Z");
67+
char format[strlen_P(formatP) + 1];
68+
strcpy_P(format, formatP);
69+
70+
char result[30];
71+
strftime(result, sizeof(result), format, last_modified);
72+
return setLastModified((const char *)result);
7073
}
7174

7275
#ifdef ESP8266
@@ -195,15 +198,15 @@ uint8_t AsyncStaticWebHandler::_countBits(const uint8_t value) const
195198
void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request)
196199
{
197200
// Get the filename from request->_tempObject and free it
198-
String filename((char*)request->_tempObject);
201+
String filename = String((char*)request->_tempObject);
199202
free(request->_tempObject);
200203
request->_tempObject = NULL;
201204
if((_username.length() && _password.length()) && !request->authenticate(_username.c_str(), _password.c_str()))
202205
return request->requestAuthentication();
203206

204207
if (request->_tempFile == true) {
205208
time_t lw = request->_tempFile.getLastWrite(); // get last file mod time (if supported by FS)
206-
if (lw) setLastModified(std::gmtime(&lw));
209+
if (lw) setLastModified(gmtime(&lw));
207210
String etag(lw ? lw : request->_tempFile.size()); // set etag to lastmod timestamp if available, otherwise to size
208211
if (_last_modified.length() && _last_modified == request->header(F("If-Modified-Since"))) {
209212
request->_tempFile.close();

0 commit comments

Comments
 (0)