Reject incomplete WebConfig confirmations under memory pressure
This commit is contained in:
1 parent
cefda42b53
commit
88bfaebb50
8 files changed
+302
-25
No files matched your search
+22
-2
@@ -23,9 +23,27 @@ struct Client {
|
||||
int localIP() const { return local_ip; }
|
||||
uint32_t getRemoteAddress() const { return remote; }
|
||||
};
|
||||
struct AsyncWebHeader {
|
||||
std::string text;
|
||||
const std::string& value() const { return text; }
|
||||
};
|
||||
struct AsyncWebServerResponse {
|
||||
int status; std::map<std::string, std::string> headers;
|
||||
void addHeader(const char* key, const char* value) { headers[key]=value; }
|
||||
int status = 200; std::map<std::string, std::string> headers;
|
||||
mutable AsyncWebHeader header_view;
|
||||
bool addHeader(const char* key, const char* value) { headers[key]=value; return true; }
|
||||
const AsyncWebHeader* getHeader(const char* key) const {
|
||||
const auto found = headers.find(key);
|
||||
if (found == headers.end()) return nullptr;
|
||||
header_view.text = found->second;
|
||||
return &header_view;
|
||||
}
|
||||
};
|
||||
struct AsyncResponseStream : AsyncWebServerResponse {
|
||||
std::string body;
|
||||
size_t available() const { return body.size(); }
|
||||
void setCode(int value) { status = value; }
|
||||
size_t write(uint8_t value) { body.push_back(char(value)); return 1; }
|
||||
size_t write(const uint8_t* bytes, size_t count) { body.append(reinterpret_cast<const char*>(bytes), count); return count; }
|
||||
};
|
||||
struct AsyncWebServerRequest {
|
||||
Client socket; bool has_client=true;
|
||||
@@ -34,6 +52,8 @@ struct AsyncWebServerRequest {
|
||||
Client* client() { return has_client ? &socket : nullptr; }
|
||||
void send(int code, const char* =nullptr, const char* content=nullptr) { status=code; reply=content ? content : ""; }
|
||||
AsyncWebServerResponse* beginResponse(int code, const char*, const char*) { response.status=code; return &response; }
|
||||
AsyncResponseStream* beginResponseStream(const char*, size_t = 0) { return new AsyncResponseStream; }
|
||||
void send(AsyncResponseStream* value) { status=value->status; response=*value; reply=value->body; delete value; }
|
||||
void send(AsyncWebServerResponse* value) { status=value->status; }
|
||||
};
|
||||
struct WebConfigServer {
|
||||
|
||||
+11
-1
@@ -60,13 +60,23 @@ struct Callback {
|
||||
void onConfigBatchStart() { ++starts; }
|
||||
void onConfigBatchEnd() { ++ends; }
|
||||
};
|
||||
struct AsyncResponseStream : std::string {
|
||||
int code = 200;
|
||||
size_t available() const { return size(); }
|
||||
void setCode(int value) { code = value; }
|
||||
bool addHeader(const char*, const char*) { return true; }
|
||||
size_t write(uint8_t value) { push_back(char(value)); return 1; }
|
||||
size_t write(const uint8_t* bytes, size_t count) { append(reinterpret_cast<const char*>(bytes), count); return count; }
|
||||
};
|
||||
struct AsyncWebServerRequest {
|
||||
int status = 0;
|
||||
std::string body, reply;
|
||||
void* _tempObject = nullptr;
|
||||
size_t contentLength() const { return body.size(); }
|
||||
void send(int code, const char*, const char* text) { status = code; reply = text; }
|
||||
void send(int code, const char* = nullptr, const char* text = "") { status = code; reply = text; }
|
||||
void send(int code, const char*, const String& text) { status = code; reply = text; }
|
||||
AsyncResponseStream* beginResponseStream(const char*, size_t = 0) { return new AsyncResponseStream; }
|
||||
void send(AsyncResponseStream* response) { status = response->code; reply = *response; delete response; }
|
||||
void payload(const std::string& text) { body = text; _tempObject = &body[0]; }
|
||||
};
|
||||
static const char SECRET_SENTINEL[] = "********";
|
||||
|
||||
+23
-3
@@ -52,19 +52,39 @@ struct Client {
|
||||
uint32_t getRemoteAddress() const { return remote; }
|
||||
};
|
||||
struct Header { String cookies; const String& value() const { return cookies; } };
|
||||
struct AsyncWebHeader {
|
||||
std::string text;
|
||||
const std::string& value() const { return text; }
|
||||
};
|
||||
struct AsyncWebServerResponse {
|
||||
int status; std::map<std::string, std::string> headers;
|
||||
void addHeader(const char* key, const char* value) { headers[key]=value; }
|
||||
int status = 200; std::map<std::string, std::string> headers;
|
||||
mutable AsyncWebHeader header_view;
|
||||
bool addHeader(const char* key, const char* value) { headers[key]=value; return true; }
|
||||
const AsyncWebHeader* getHeader(const char* key) const {
|
||||
const auto found = headers.find(key);
|
||||
if (found == headers.end()) return nullptr;
|
||||
header_view.text = found->second;
|
||||
return &header_view;
|
||||
}
|
||||
};
|
||||
struct AsyncResponseStream : AsyncWebServerResponse {
|
||||
std::string body;
|
||||
size_t available() const { return body.size(); }
|
||||
void setCode(int value) { status = value; }
|
||||
size_t write(uint8_t value) { body.push_back(char(value)); return 1; }
|
||||
size_t write(const uint8_t* bytes, size_t count) { body.append(reinterpret_cast<const char*>(bytes), count); return count; }
|
||||
};
|
||||
struct AsyncWebServerRequest {
|
||||
Client socket; bool has_client=true;
|
||||
Header header; std::string body; void* _tempObject=nullptr;
|
||||
Header header; std::string body, reply; void* _tempObject=nullptr;
|
||||
int status=0; AsyncWebServerResponse response{};
|
||||
Client* client() { return has_client ? &socket : nullptr; }
|
||||
bool hasHeader(const char*) const { return !header.cookies.empty(); }
|
||||
Header* getHeader(const char*) { return &header; }
|
||||
void send(int code, const char* =nullptr, const char* =nullptr) { status=code; }
|
||||
AsyncWebServerResponse* beginResponse(int code, const char*, const char*) { response.status=code; return &response; }
|
||||
AsyncResponseStream* beginResponseStream(const char*, size_t = 0) { return new AsyncResponseStream; }
|
||||
void send(AsyncResponseStream* value) { status=value->status; response=*value; reply=value->body; delete value; }
|
||||
void send(AsyncWebServerResponse* value) { status=value->status; }
|
||||
void password(const char* value) { body=std::string("{\"password\":\"")+value+"\"}"; _tempObject=body.data(); }
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user