WiFi WebServer for ESP8266
Fork of ESP8266_WebServer by
Diff: ESP8266_WebServer.cpp
- Revision:
- 3:4ef7db7a95a7
- Parent:
- 2:6079554681d6
- Child:
- 4:759de84e790b
- Child:
- 5:48b7fd921bef
--- a/ESP8266_WebServer.cpp Thu Jan 01 14:59:13 2015 +0000 +++ b/ESP8266_WebServer.cpp Thu Jan 01 16:27:58 2015 +0000 @@ -199,11 +199,17 @@ } void ESP8266_WebServer::SendReply(int linkID, std::string reply, const char* mimeType) { - SendReply(linkID, reply.c_str(), reply.length(), mimeType); + SendReply(linkID, reply.c_str(), reply.length(), mimeType, 60); } void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType) { - sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n", mimeType, replySize); + SendReply(linkID, reply, replySize, mimeType, 600); +} +void ESP8266_WebServer::SendReply(int linkID, char const* reply, const char* mimeType, int maxAge) { + SendReply(linkID, reply, strlen(reply), mimeType, maxAge); +} +void ESP8266_WebServer::SendReply(int linkID, char const* reply, int replySize, const char* mimeType, int maxAge) { + sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, replySize, maxAge); sendResponse(linkID, strlen(response)); char const* sendPtr = reply; int bytesSent = 0; @@ -221,7 +227,10 @@ } void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType) { - sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\n\r\n", mimeType, file->flen()); + SendFile(linkID, file, mimeType, 86400); +} +void ESP8266_WebServer::SendFile(int linkID, FileHandle* file, const char* mimeType, int maxAge) { + sprintf(response, "HTTP/1.1 200 OK\r\nContent-Type:%s\r\nContent-Length: %d\r\nCache-Control:max-age=%d\r\n\r\n", mimeType, file->flen(), maxAge); sendResponse(linkID, strlen(response)); int numBytes = file->read(response, sizeof(response)); while( numBytes > 0) {