This commit is contained in:
Proddy
2024-03-12 23:08:57 +01:00
parent 0bd57973c5
commit be6bb1de6a
4 changed files with 5 additions and 39 deletions

View File

@@ -855,12 +855,6 @@ AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const
return beginResponse_P(code, contentType, (const uint8_t *)content, strlen_P(content), callback); return beginResponse_P(code, contentType, (const uint8_t *)content, strlen_P(content), callback);
} }
// added by proddy
AsyncWebServerResponse *
AsyncWebServerRequest::beginResponse(const String & contentType, const uint8_t * content, size_t len) {
return new AsyncResponse(contentType, content, len);
}
void AsyncWebServerRequest::send(int code, const String & contentType, const String & content) { void AsyncWebServerRequest::send(int code, const String & contentType, const String & content) {
send(beginResponse(code, contentType, content)); send(beginResponse(code, contentType, content));
} }

View File

@@ -145,20 +145,6 @@ class AsyncProgmemResponse : public AsyncAbstractResponse {
virtual size_t _fillBuffer(uint8_t * buf, size_t maxLen) override; virtual size_t _fillBuffer(uint8_t * buf, size_t maxLen) override;
}; };
// added by proddy
class AsyncResponse : public AsyncAbstractResponse {
private:
const uint8_t * _content;
size_t _readLength;
public:
AsyncResponse(const String & contentType, const uint8_t * content, size_t len);
bool _sourceValid() const {
return true;
}
virtual size_t _fillBuffer(uint8_t * buf, size_t maxLen) override;
};
class cbuf; class cbuf;
class AsyncResponseStream : public AsyncAbstractResponse, public Print { class AsyncResponseStream : public AsyncAbstractResponse, public Print {

View File

@@ -746,20 +746,6 @@ size_t AsyncProgmemResponse::_fillBuffer(uint8_t * data, size_t len) {
return left; return left;
} }
// added by proddy
AsyncResponse::AsyncResponse(const String & contentType, const uint8_t * content, size_t len)
: AsyncAbstractResponse(nullptr) {
_code = 200;
_content = content;
_contentType = contentType;
_contentLength = len;
_readLength = len;
}
size_t AsyncResponse::_fillBuffer(uint8_t * data, size_t len) {
memcpy(data, _content, len);
return len;
}
/* /*
* Response Stream (You can print/write/printf to it, up to the contentLen bytes) * Response Stream (You can print/write/printf to it, up to the contentLen bytes)
* */ * */

View File

@@ -27,7 +27,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
static char last_modified[50]; static char last_modified[50];
sprintf(last_modified, "%s %s CET", __DATE__, __TIME__); sprintf(last_modified, "%s %s CET", __DATE__, __TIME__);
WWWData::registerRoutes([server](const String & uri, const String & contentType, const uint8_t * content, size_t len, const String & hash) { WWWData::registerRoutes([server](const char * uri, const String & contentType, const uint8_t * content, size_t len, const String & hash) {
ArRequestHandlerFunction requestHandler = [contentType, content, len, hash](AsyncWebServerRequest * request) { ArRequestHandlerFunction requestHandler = [contentType, content, len, hash](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified) // Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").indexOf(last_modified) > 0) { if (request->header("If-Modified-Since").indexOf(last_modified) > 0) {
@@ -36,7 +36,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
return request->send(304); return request->send(304);
} }
AsyncWebServerResponse * response = request->beginResponse(contentType, content, len); AsyncWebServerResponse * response = request->beginResponse_P(200, contentType, content, len);
response->addHeader("Content-Encoding", "gzip"); response->addHeader("Content-Encoding", "gzip");
// response->addHeader("Content-Encoding", "br"); // only works over HTTPS // response->addHeader("Content-Encoding", "br"); // only works over HTTPS
@@ -47,10 +47,10 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
request->send(response); request->send(response);
}; };
server->on(uri.c_str(), HTTP_GET, requestHandler); server->on(uri, HTTP_GET, requestHandler);
// Serving non matching get requests with "/index.html" // Serving non matching get requests with "/index.html"
// OPTIONS get a straight up 200 response // OPTIONS get a straight up 200 response
if (uri.equals("/index.html")) { if (strncmp(uri, "/index.html", 11) == 0) {
server->onNotFound([requestHandler](AsyncWebServerRequest * request) { server->onNotFound([requestHandler](AsyncWebServerRequest * request) {
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET) {
requestHandler(request); requestHandler(request);