ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_ESP32
3
4#include <esp_http_server.h>
5#include <span>
6#include <string>
8
10
13size_t url_decode(char *str);
14
15bool request_has_header(httpd_req_t *req, const char *name);
16optional<std::string> request_get_header(httpd_req_t *req, const char *name);
19size_t request_get_header_to(httpd_req_t *req, const char *name, std::span<char> buf);
20optional<std::string> query_key_value(const char *query_url, size_t query_len, const char *key);
21bool query_has_key(const char *query_url, size_t query_len, const char *key);
22
23// Helper function for case-insensitive character comparison
24inline bool char_equals_ci(char a, char b) { return ::tolower(a) == ::tolower(b); }
25
26// Helper function for case-insensitive string region comparison
27bool str_ncmp_ci(const char *s1, const char *s2, size_t n);
28
29// Bounded case-insensitive string search (like strcasestr but length-bounded)
30const char *strcasestr_n(const char *haystack, size_t haystack_len, const char *needle);
31
32} // namespace esphome::web_server_idf
33#endif // USE_ESP32
const char * key
bool query_has_key(const char *query_url, size_t query_len, const char *key)
Definition utils.cpp:79
bool char_equals_ci(char a, char b)
Definition utils.h:24
optional< std::string > request_get_header(httpd_req_t *req, const char *name)
Definition utils.cpp:36
size_t request_get_header_to(httpd_req_t *req, const char *name, std::span< char > buf)
Copy a header value into buf, nul-terminated, without heap allocation.
Definition utils.cpp:53
optional< std::string > query_key_value(const char *query_url, size_t query_len, const char *key)
Definition utils.cpp:62
const char * strcasestr_n(const char *haystack, size_t haystack_len, const char *needle)
Definition utils.cpp:102
bool str_ncmp_ci(const char *s1, const char *s2, size_t n)
Definition utils.cpp:92
size_t url_decode(char *str)
Decode URL-encoded string in-place (e.g., %20 -> space, + -> space) Returns the new length of the dec...
Definition utils.cpp:11
bool request_has_header(httpd_req_t *req, const char *name)
Definition utils.cpp:34