[web_server_idf] Add const char* overloads for getParam/hasParam to avoid temporary string allocations (#13746)
This commit is contained in:
1 parent
18f7e0e6b3
commit
b8b072cf86
4 files changed
+20
-15
No files matched your search
@@ -73,18 +73,15 @@ optional<std::string> request_get_url_query(httpd_req_t *req) {
|
||||
return {str};
|
||||
}
|
||||
|
||||
optional<std::string> query_key_value(const std::string &query_url, const std::string &key) {
|
||||
if (query_url.empty()) {
|
||||
optional<std::string> query_key_value(const char *query_url, size_t query_len, const char *key) {
|
||||
if (query_url == nullptr || query_len == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto val = std::unique_ptr<char[]>(new char[query_url.size()]);
|
||||
if (!val) {
|
||||
ESP_LOGE(TAG, "Not enough memory to the query key value");
|
||||
return {};
|
||||
}
|
||||
// Use stack buffer for typical query strings, heap fallback for large ones
|
||||
SmallBufferWithHeapFallback<256, char> val(query_len);
|
||||
|
||||
if (httpd_query_key_value(query_url.c_str(), key.c_str(), val.get(), query_url.size()) != ESP_OK) {
|
||||
if (httpd_query_key_value(query_url, key, val.get(), query_len) != ESP_OK) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user