7#include "http_parser.h"
12namespace web_server_idf {
14static const char *
const TAG =
"web_server_idf_utils";
18 for (; *str; str++, ptr++) {
21 if (
parse_hex(str, 2,
reinterpret_cast<uint8_t *
>(&buf), 1) == 2) {
28 }
else if (*str ==
'+') {
37bool request_has_header(httpd_req_t *req,
const char *name) {
return httpd_req_get_hdr_value_len(req, name); }
40 size_t len = httpd_req_get_hdr_value_len(req, name);
48 auto res = httpd_req_get_hdr_value_str(req, name, &str[0],
len + 1);
57 auto len = httpd_req_get_url_query_len(req);
65 auto res = httpd_req_get_url_query_str(req, &str[0],
len + 1);
67 ESP_LOGW(TAG,
"Can't get query for request: %s", esp_err_to_name(res));
75 if (query_url.empty()) {
79 auto val = std::unique_ptr<char[]>(
new char[query_url.size()]);
81 ESP_LOGE(TAG,
"Not enough memory to the query key value");
85 if (httpd_query_key_value(query_url.c_str(), key.c_str(),
val.get(), query_url.size()) != ESP_OK) {
95 for (
size_t i = 0; i < n; i++) {
104const char *
stristr(
const char *haystack,
const char *needle) {
109 size_t needle_len = strlen(needle);
110 if (needle_len == 0) {
114 for (
const char *p = haystack; *p; p++) {
bool char_equals_ci(char a, char b)
void url_decode(char *str)
optional< std::string > request_get_url_query(httpd_req_t *req)
optional< std::string > request_get_header(httpd_req_t *req, const char *name)
bool str_ncmp_ci(const char *s1, const char *s2, size_t n)
optional< std::string > query_key_value(const std::string &query_url, const std::string &key)
const char * stristr(const char *haystack, const char *needle)
bool request_has_header(httpd_req_t *req, const char *name)
Providing packet encoding functions for exchanging data with a remote host.
size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count)
Parse bytes from a hex-encoded string into a byte array.